register_activation_hook isn’t adding table to DB

I’ve started my first plugin and I need to store values returned from an API call to a database. But before I do that, I need to be able to make a database table. I have the following code in a file that is required of the main plugin file:

register_activation_hook(__FILE__, 'wtmcf_activation');
function wtmcf_activation() {
    //setup DB Tables
    global $wpdb;

    $table_name = $wpdb->prefix . Constants::TABLENAME;

    $charset_collate = $wpdb->get_charset_collate();

    $sql = "CREATE TABLE $table_name (
      id mediumint(9) NOT NULL AUTO_INCREMENT,
      event_id text NOT NULL,
      event_date mediumint(8) DEFAULT '00000000' NOT NULL,
      event_unique mediumint(13) NOT NULL,
      name tinytext NOT NULL,
      PRIMARY KEY  (id)
    ) $charset_collate;";

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

For some reason, the table is not being created. What could be stopping this?

Read more here: register_activation_hook isn’t adding table to DB

Leave a Reply

Your email address will not be published. Required fields are marked *