Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
You might be interested in these. –  s_ha_dum Apr 1 at 23:31

1 Answer 1

up vote 2 down vote accepted

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)
);";
share|improve this answer
    
Brilliant! Thanks very much. –  Richard Smith Apr 1 at 23:30
    
@RichardSmith mark the question as solved. –  Farzad Apr 2 at 4:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.