[wp-trac] [WordPress Trac] #27062: dbDelta error on plugin activation/deactivation/reactivation

WordPress Trac noreply at wordpress.org
Thu Jul 24 20:41:09 UTC 2014


#27062: dbDelta error on plugin activation/deactivation/reactivation
--------------------------+------------------------------
 Reporter:  colinhahn     |       Owner:
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Database      |     Version:  3.8.1
 Severity:  normal        |  Resolution:  invalid
 Keywords:                |     Focuses:
--------------------------+------------------------------
Changes (by jdgrimes):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 According to [https://dev.mysql.com/doc/refman/5.1/en/create-table.html
 the MySQL manual], the syntax for the `PRIMARY KEY` is like this:

 {{{
 PRIMARY KEY [index_type] (index_col_name,...)
 }}}

 And for reference, the `index_type` and `index_col_name` definitions:

 {{{
 index_col_name:
     col_name [(length)] [ASC | DESC]

 index_type:
     USING {BTREE | HASH}
 }}}

 So your SQL is not correct:

 {{{
 PRIMARY KEY  id (id)
 }}}

 I've actually been doing mine the same way, but now I realize it's not
 right. You can't name a `PRIMARY` key, it's name is always `PRIMARY`
 ([https://dev.mysql.com/doc/refman/5.1/en/create-
 table.html#idm47837678294528 1]). The only think that should be between
 there is the `index_type`. So the correct syntax is:

 {{{
 PRIMARY KEY  (id)
 }}}

 And indeed, this works with `dbDelta()` and doesn't cause this error.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/27062#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list