CREATE TABLE with dbDelta does not create table

Question

I based this code from the codex on the docs. I placed it in my main plugin file but it’s not creating the database table. Have I missed something?



    // Database setup and hooks
    
    function core_createdb() {
        global $wpdb;
        $table_name = $wpdb->prefix . 'core_logs';
        $wpdb_collate = $wpdb->collate;
        $sql = 
            "CREATE TABLE {$table_name} (
            timestamp DATE NOT NULL,
            logid INT NOT NULL AUTO_INCREMENT,
            userid INT DEFAULT NULL,
            actiontype TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'undefined',
            userip VARCHAR CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'unknown',
            actioncontent VARCHAR CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
            botactioncomment VARCHAR CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
            botactionmade BOOLEAN DEFAULT '0',
            flaglevel TINYINT DEFAULT '0',
            PRIMARY KEY  (logid),
            KEY useridkey (userid)
            )
            COLLATE {$wpdb_collate}";
    
        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        dbDelta($sql);
    
        $success = empty($wpdb->last_error);
    
        return $success;
    }
    
    // Create Database
    
    add_action('init', 'core_createdb');

0
, , FCD 1 year 2020-07-19T08:11:18-05:00 0 Answers 57 views 0

Leave an answer

Browse
Browse