Plugins custom table not being created on activation

Question

I’m developing a WordPress plugin and for some reason it’s not creating a custom table on activation.

Here’s my code, I had to change the table name, field names, etc.:

function exPlugininstaller() {
    global $wpdb;
    $table_name =  $wpdb->prefix . 'extable';
    $extable_db_version = '1.0.0';
    $charset_collate = $wpdb->get_charset_collate();
          
    $sql="CREATE TABLE ". $table_name . ' (
            ID int NOT NULL AUTO_INCREMENT,
            Field1 bigint(20) NOT NULL UNIQUE,
            Field2 varchar(255) NOT NULL,
            Field3 date DEFAULT GETDATE(),
            Field4 varchar(255) NOT NULL,
            Field5 tinyint NOT NULL,
            Field6 varchar(255) NOT NULL,
            Field7 varchar(30) NOT NULL,
            Field8 text DEFAULT "",
            Field9 varchar(255) NOT NULL,
            Field10 ENUM("option 1", "option 2", "option 3", "option 4", "option 5", "option 6", "option 7") NOT NULL,
            Field11 varchar(255) NOT NULL,
            Field12 ENUM("option 1", "option 2", "option 3") NOT NULL,
            Field13 ENUM("option 1", "option 2", "option 3") NOT NULL,
            Field14 ENUM("Under $12,000.00", "$12,000.00-$25,000", "$25,000.00-$45,000.00", "Over $45,000.00") NOT NULL,
            Field15 BOOL NOT NULL,
            Field16 varchar(255) DEFAULT "n/a",
            Field17 BOOL,
            Field18 BOOL NOT NULL,
            Field19 text DEFAULT "n/a",
            Field20 tinyint DEFAULT 0,
            Field21 tinyint DEFAULT 0,
            Field22 text NOT NULL,
            Field23 ENUM("No", "option 1", "option 2", "option 3"),
            Field24 ENUM("No", "Yes", "n/a") DEFAULT "n/a",
            Field25 varchar(255) DEFAULT "n/a",
            Field26 smallmoney,
            Field27 varchar(255),
            Field28 tinyint,
            Field29 varchar(255),
            Field30 text NOT NULL,
            Field31 varchar(255),
            Field32 varchar(255),
            Field33 varchar(255),
            Field34 tinyint DEFAULT 0,
            Field35 BOOL NOT NULL,
            Field36 BOOL,
            PRIMARY KEY  (ID)
          ) '. $charset_collate .';';

      require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
      dbDelta( $sql );
      add_option( 'extable_db_version', $extable_db_version );
    }
  
  // register activation hook for installer function
  register_activation_hook(__file__, 'exPlugininstaller');

Yes, I know others have asked this in the past. No, checking those answers didn’t give me any clarity into what’s going on.

0
TheJman 4 weeks 2021-06-28T09:47:04-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse