Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#10994 closed defect (bug) (fixed)

2.8.5 Multiple primary key Error

Reported by: frumph's profile Frumph Owned by:
Milestone: 2.9 Priority: high
Severity: blocker Version: 2.8.4
Component: Upgrade/Install Keywords: has-patch
Focuses: Cc:

Description

[21-Oct-2009 07:19:31] WordPress database error Multiple primary key defined for query ALTER TABLE wp_options ADD PRIMARY KEY (option_id,blog_id,option_name) made by wp_upgrade, make_db_current_silent, dbDelta

This was given after upgrading to 2.8.5

Attachments (1)

wp-admin-includes-upgrade.php.patch (638 bytes) - added by miqrogroove 15 years ago.

Download all attachments as: .zip

Change History (7)

#1 @miqrogroove
15 years ago

  • Milestone changed from Unassigned to 2.9
  • Priority changed from normal to high
  • Severity changed from normal to critical

SQL errors should have high priority for 2.9. Duplicate primary key errors are usually caused by failure to check key type and key existence before issuing an ALTER command.

Frumph, are you able to add steps to reproduce this error?

#2 @miqrogroove
15 years ago

At first glance, function dbDelta() appears to issue the ALTER command as follows:

if(!(($aindex = array_search($index_string, $indices)) === false)) {
    unset($indices[$aindex]);
}
// For every remaining index specified for the table
foreach ( (array) $indices as $index ) {
    // Push a query line into $cqueries that adds the index to that table
    $cqueries[] = "ALTER TABLE {$table} ADD $index";
}

That logic is extremely deficient if it is being used in production to modify table indices.

#3 @miqrogroove
15 years ago

After a little more digging, I figured out that some of the indices are handled by function pre_schema_upgrade(), and the code in there does not match the error given by OP. I'm starting to doubt that error could be reproduced.

#4 @miqrogroove
15 years ago

  • Severity changed from critical to blocker

Just coincidentally, this was fixed by [12217] a few hours ago. That's the first revision containing both pre_schema_upgrade() and the correct SQL syntax. Unfortunately, that revision introduced a logic error affecting one of the 2.9-rare schemas, so I'd like to see that patched before this ticket closes.

See also [11883].

#5 @miqrogroove
15 years ago

  • Keywords has-patch added

#6 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [12232]) Fix db version logic error. Props miqrogroove. fixes #10994

Note: See TracTickets for help on using tickets.