Opened 4 years ago
Closed 4 years ago
#10994 closed defect (bug) (fixed)
2.8.5 Multiple primary key Error
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | 2.9 |
| Component: | Upgrade/Install | Version: | 2.8.4 |
| Severity: | blocker | Keywords: | has-patch |
| 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)
Change History (7)
comment:1
miqrogroove — 4 years ago
- Milestone changed from Unassigned to 2.9
- Priority changed from normal to high
- Severity changed from normal to critical
comment:2
miqrogroove — 4 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.
comment:3
miqrogroove — 4 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.
comment:4
miqrogroove — 4 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].
miqrogroove — 4 years ago
comment:5
miqrogroove — 4 years ago
- Keywords has-patch added

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?