0

Okay so I must have read hundreds of wordpress answers, google results etc on different people having trouble with dbDelta creating tables for their plugins.

Ive tried many variations based off of those answers to see if it would do the trick but this code below does not seem to create the table. Even though the returned data from dbDelta says it created the table, if there is any help anyone can give me or see the error that I've made, I would be very grateful.

function activation() {
  // Install table
  global $wpdb;

  $sql = "CREATE TABLE ".$this->table_name." (
    id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
    PRIMARY KEY (id),
      user_id BIGINT(20) NOT NULL UNSIGNED,
      KEY user_id (user_id),
        created DATETIME DEFAULT '0000-00-00 00:00:00'  NOT NULL,
        url VARCHAR(55) DEFAULT '' NOT NULL,
  );";

  var_dump($sql);

  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  var_dump(dbDelta( $sql ));

  add_option( "invite_db_version", $invite_db_version );
}

This function is registered to the activation hook in the constructor of my plugin class register_activation_hook( __FILE__, array( &$this, 'activation' ) );

  • Tried to answer my own question but wont let me for another 7 hrs, here is the sql statement that worked for others: $sql = "CREATE TABLE ".$this->table_name." ( id MEDIUMINT(9) NOT NULL AUTO_INCREMENT, user_id BIGINT(20) UNSIGNED NOT NULL, created DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL, url VARCHAR(55) DEFAULT '' NOT NULL, KEY user_id (user_id), PRIMARY KEY (id) );"; – mihok May 29 '13 at 12:59
0

You appear to have answered your own question in a comment, but yes, the SQL is wrong. KEYs must come at the end of the statement, after the column definitions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.