wp_options table has duplicate rows and primary key / autoincrement has been removed

I’ve noticed that in my development instance of WordPress that wp_options contains duplicate rows. After some more investigation I found that the primary_key and auto_increment restraints were removed from the option_id column.

Does anyone know how this could have happened? I certainly didn’t go in and remove these myself. Some ideas:

  • Bad database import
  • Plugin modified the database
  • WordPress update failed

I found this wp.stackexchange question which describes the same problem, but the answers don’t seem to explain how it could have happened in the first place.

Thank you for your assistance brainstorming what would have triggered this problem. I’d like to prevent it from occurring in the future.

2 Answers
2

Well after a lot of digging, I think I uncovered what happened. The clue came from the fact that I noticed it was wp_options and all alphabetically subsequent tables that lost their primary keys.

On import, first the tables are created. Next it goes through all those tables in alphabetical order and applies the primary keys and auto_increment flags. It would seem the application of keys and flags was interrupted just prior to wp_options and the failure cascaded down.

Leave a Comment