WordPress.org

Support

Support » How-To and Troubleshooting » dbDelta: Issues with upgrading tables with composite primary key

dbDelta: Issues with upgrading tables with composite primary key

  • I typically don’t have any issues with dbDelta. However, I came across a problem during upgrade that has to do with using a composite primary key. The first time the below code is run, the table is deployed with no errors. However, the moment I run deployment again with dbDelta, it bombs out. I’m currently on 3.3.1.

    Code:
    require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);

    function yobik_whatupwiththis () {
    	global $wpdb;
    
    	$sql[] = "CREATE TABLE my_table (
    		yo_id int(11) NOT NULL default 0,
    		bik_id smallint(6) NOT NULL default 0,
    		wha_id smallint(6) NOT NULL default 0,
    		tus_id smallint(6) NOT NULL default 0,
    		PRIMARY KEY (yo_id, bik_id))";
    
    	dbDelta($sql);
    }

    Resulting Error:
    WordPress database error: [Multiple primary key defined]
    ALTER TABLE my_table ADD PRIMARY KEY (yo_id, bik_id)

    Wondering if somebody has come across this issue.

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘dbDelta: Issues with upgrading tables with composite primary key’ is closed to new replies.
Skip to toolbar