mysql - Plugin not creating 2nd table on activation -


i created first table plugin, , after working on adding more features realized needed add second table additional type of data.

troubleshooting efforts far have resolved issue dbdelta() not using same variable name sql data, running dbdelta() both combined sql var ($setup_sql .= '...' instead of $setup_sql = '...'), , running code simple function rather class.

i tried running single table creation different name, check code worked, , still didn't create table.

i have had no errors running through these tests, , intents , purposes seems wordpress doesn't allow plugin create more 1 table - know that's not case.

    class activation_setup {     public static function wpd_activate() {         global $wpdb;         $charset_collate = $wpdb->get_charset_collate();         require_once( abspath . 'wp-admin/includes/upgrade.php' );          $wpd_table_trig = $wpdb->prefix . 'wpd_triggers';         $setup_sql_trig = "create table $wpd_table_trig (           id int(11 ) not null auto_increment,           trigger varchar(255) default null,           popup varchar(255) default null,           notify varchar(255) default null,           unique key id (id)         ) $charset_collate;";         dbdelta( $setup_sql_trig );          $wpd_table_sel = $wpdb->prefix . 'wpd_selections';         $setup_sql_sel = "create table $wpd_table_sel (           id int(11 ) not null auto_increment,           selected varchar(255) default null,           session varchar(255) default null,           ip varchar(255) default null,           page varchar(255) default null,           date varchar(255) default null,           unique key id (id)         ) $charset_collate;";         dbdelta( $setup_sql_sel );          update_option('wpd_activated',true);     } } $activation_setup = new activation_setup(); register_activation_hook( __file__ , array( $activation_setup, 'wpd_activate' ) ); 

i'm going absolutely nuts trying work out why code doesn't add second table, after stripping out duplicate table code , running different table name.

i've through ton of blog posts , stack answers trying bottom of it.

any fantastic.

issue table definition. you've written trigger in table definition keyword mysql.
issue.
problem solved change.
use "`" when writing field name.

 class activation_setup {     public static function wpd_activate() {         global $wpdb;         $charset_collate = $wpdb->get_charset_collate();         require_once( abspath . 'wp-admin/includes/upgrade.php' );          $wpd_table_trig = $wpdb->prefix . 'wpd_triggers';         $setup_sql_trig = "create table $wpd_table_trig (           `id` int(11 ) not null auto_increment,           `trigger` varchar(255) default null,           `popup` varchar(255) default null,           `notify` varchar(255) default null,           unique key id (id)         ) $charset_collate;";         dbdelta( $setup_sql_trig );          $wpd_table_sel = $wpdb->prefix . 'wpd_selections';         $setup_sql_sel = "create table $wpd_table_sel (           `id` int(11 ) not null auto_increment,           `selected` varchar(255) default null,           `session` varchar(255) default null,           `ip` varchar(255) default null,           `page` varchar(255) default null,           `date` varchar(255) default null,           unique key id (id)         ) $charset_collate;";         dbdelta( $setup_sql_sel );       } } $activation_setup = new activation_setup(); register_activation_hook( __file__ , array( $activation_setup, 'wpd_activate' ) );   

if want make sure issue trigger remove "`" trigger field , again activate plugin.


Comments