Why doesn’t this code add a table to my database?

To get to the point, I’m trying to add a database table upon installation of my plugin. Here’s my code:

global $scimp_db_version;
$scimp_db_version = "1.0";

function scimp_install () {

global $wpdb;

$table_name = $wpdb->prefix . "scimp"; 

$sql = "CREATE TABLE $table_name (
        id int NOT NULL AUTO_INCREMENT,
        feedurl text NOT NULL,
        category text NOT NULL,
        );";

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

add_option("scimp_db_version", $scimp_db_version);

}

register_activation_hook( __FILE__, 'scimp_install' )

Needless to say, this isn’t working. The table isn’t being created. I’m hoping that there’s just something simple that I’m missing after looking at it too long. Can anyone see anything wrong here?

Related posts

Leave a Reply

1 comment

  1. A key must be defined for a table by using a single column, or multiple. So on your code, you need to a line to the sql KEY id (id)

    $sql = "CREATE TABLE $table_name (
        id int NOT NULL AUTO_INCREMENT,
        feedurl text NOT NULL,
        category text NOT NULL,
        KEY  id (id)
    );";