Opened 9 years ago
Closed 9 years ago
#34471 closed defect (bug) (invalid)
dbDelta fails with existing tables and indices
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Database | Keywords: | |
Focuses: | Cc: |
Description
Referring "wp-admin/includes/upgrade.php:2231" @WP 4.3.1
Take this Query:
CREATE TABLE wp_termmeta ( meta_id bigint(20) NOT NULL AUTO_INCREMENT, term_id bigint(20) NOT NULL default 0, meta_key varchar(255) DEFAULT NULL, meta_value longtext DEFAULT NULL ) UNIQUE KEY meta_id (meta_id)
Running it multiple times with dbDelta will fail in an invalid Query:
ALTER TABLE wp_termmeta ADD
It creates queries for indices. But as I debug the variable $indices looks like this:
$indices = array( 1 => "", 2 => "", );
I don't know why it is "empty" but this might be a hotfix:
$indices = array_filter($indices);
Change History (1)
Note: See
TracTickets for help on using
tickets.
Hi there!
This isn't a valid
CREATE TABLE
statement - theUNIQUE KEY
line needs to be inside the brackets.dbDelta()
also doesn't play nicely with blank lines - seewp-admin/includes/schema.php
for examples of how to writedbDelta()
-friendly table definitions.dbDelta()
is not intended to parse all possible table definitions, just the subset needed for WordPress tables. While we're open to expanding what it supports, of course, for standard table definitions, you need to adhere to the formats it supports.