Problem with dbDelta
-
on activation my plugin is generating 751 bytes of unexpected output. The issue is caused by my activation hook which includes the following:
$charset_collate = $wpdb->get_charset_collate(); $sql[] = "CREATE TABLE {$links_table_name} ( 'id' bigint unsigned NOT NULL auto_increment, 'cloud_id' char(32) NOT NULL, 'user_id' bigint unsigned NOT NULL, 'category_id' tinyint NOT NULL, 'url' varchar(255) NOT NULL default '', 'url_hash' char(32) NOT NULL, 'target' varchar(25) default NULL, 'rel' varchar(25) default NULL, 'slug' varchar(255) NOT NULL, 'name' varchar(255) NOT NULL, 'description' text, 'status' tinyint(1) NOT NULL default '1', 'vote_count' smallint NOT NULL default '0', 'vote_total' smallint NOT NULL default '0', 'popularity' mediumint UNSIGNED NOT NULL default '0', 'embed_service' char(32) default null, 'embed_status' tinyint(1) default '0', 'embed_data' text, 'date_created' datetime NOT NULL, 'date_updated' timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY ('id'), UNIQUE 'cloud_id' ('cloud_id'), KEY 'user_id' ('user_id'), KEY 'category_id' ('category_id'), KEY 'url_hash' ('url_hash'), KEY 'slug' ('slug'), KEY 'name' ('name'(20)), KEY 'status' ('status'), KEY 'vote_count' ('vote_count'), KEY 'vote_total' ('vote_total'), KEY 'popularity' ('popularity'), KEY 'date_created' ('date_created'), KEY 'date_updated' ('date_updated') ) {$charset_collate};"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql);
Looking at my error log I’m seeing the following errors:
[18-Mar-2019 08:54:25 UTC] 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 ‘(
)’ at line 1 for query ALTER TABLE EJcStfaZbp_links ADD
(
) made by activate_plugin
[18-Mar-2019 08:54:25 UTC] PHP Notice: Undefined index: column_name in /wp-admin/includes/upgrade.php on line 2713
[18-Mar-2019 08:54:25 UTC] PHP Notice: Undefined index: index_columns in /wp-admin/includes/upgrade.php on line 2685
[18-Mar-2019 08:54:25 UTC] PHP Notice: Undefined index: index_name in /wp-admin/includes/upgrade.php on line 2682
[18-Mar-2019 08:54:25 UTC] PHP Notice: Undefined index: index_type in /wp-admin/includes/upgrade.php on line 2676I’m assuming there’s an error in my SQL syntax but I can’t see the error, am I missing something?
Thanks in advance.
- The topic ‘Problem with dbDelta’ is closed to new replies.