I am working on my first WP plugin, and trying to create a SQL table first when activation the plugin. In my plugins/custom-plugin/custom-plugin.php I’ve put the following:

// Create database tables
function lyriqa_install() {
    global $wpdb;

    $song_table =   $wpdb->prefix . 'songs';

    $charset_collate = $wpdb->get_charset_collate();

    $sql = "CREATE TABLE $song_table (
            id mediumint(9) NOT NULL AUTO_INCREMENT,
            title varchar(255) NOT NULL,
            author varchar(255) NOT NULL,
            uid int(6) NOT NULL,
            created timestamp DEFAULT 'CURRENT_TIMESTAMP' NOT NULL,
            PRIMARY KEY  (id)
    ) $charset_collate;";

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

register_activation_hook( __FILE__, 'lyriqa_install' );

Which was supposed to create a wp_songssql table. Plugin activation goes just alright, however a new table is not created. I followed the instructions at https://codex.wordpress.org/Creating_Tables_with_Plugins to get it down. Any advice would be apreciated.

Read more here: Fail to create a table when activating a plugin in WP


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: