[wp-trac] [WordPress Trac] #38936: Alter Table Always Expects a COLUMN; Crashes on a CONSTRAINT
WordPress Trac
noreply at wordpress.org
Thu Nov 24 17:25:14 UTC 2016
#38936: Alter Table Always Expects a COLUMN; Crashes on a CONSTRAINT
--------------------------+-----------------------------
Reporter: philsown | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version: 4.6.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hello,
I'm attempting to activate a plugin I'm developing. The database creation
scripts have CONSTRAINTs on them. When I attempt to reactivate, I'm
getting this error:
{{{
WordPress database error: [You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax
to use near 'CONSTRAINT `mytable_mycol_foreign` FOREIGN KEY (`mycol' at
line 1]
ALTER TABLE wp_mytable ADD COLUMN CONSTRAINT `mytable_mycol_foreign`
FOREIGN KEY (`mycol`) REFERENCES `myothertable` (`myothercol`)
}}}
As you can see the SQL error lies in `ADD COLUMN CONSTRAINT`.
This is being generated in `wp-admin/includes/upgrade.php` around line
2392
{{{#!php
<?php
// For every remaining field specified for the table.
foreach ($cfields as $fieldname => $fielddef) {
// Push a query line into $cqueries that adds the field to that
table.
$cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
$for_update[$table.'.'.$fieldname] = 'Added column
'.$table.'.'.$fieldname;
}
}}}
`ADD COLUMN` is hardcoded and is creating this SQL error. I googled for a
solution but didn't find anything.
I've tried it with the constraints being part of the full table creation
statement, and also as a stand alone statement, with the same results.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38936>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list