WordPress DB error: Multiple primary key defined

1.5k Views Asked by At

When I try to activate my custom plugin, I receive the error below:

WordPress database error Multiple primary key defined for query ALTER TABLE temp CHANGE COLUMN id id int(11) UNSIGNED AUTO_INCREMENT PRIMARY

private function runDbMigration_20() {
    $sql = "CREATE TABLE " . PREFIX . "subscribers (
    id int(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,     
    name tinytext NOT NULL,
    email text NOT NULL,
            secretkey text NOT NULL,
            random_key text NOT NULL,
            onehourmailsent int(1) NOT NULL DEFAULT 0,
            onedaymailsent int(1) NOT NULL DEFAULT 0,
            wbstartingmailsent int(1) NOT NULL DEFAULT 0,
            replaymailsent int(1) NOT NULL DEFAULT 0,
            temp_id int(11) NOT NULL,
            exact_time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
            watch_day varchar(3),
            watch_time time,
            time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
            last_seen datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
            active int(1) UNSIGNED NOT NULL DEFAULT 1,
            high_five int(1) UNSIGNED NOT NULL DEFAULT 0,
            attended int(1) UNSIGNED NOT NULL DEFAULT 0
)" . $this->CHARSET_COLLATE . ";";
    return $this->calldbDelta($sql);
}

Please, can some one help me how to resolve this error?

1

There are 1 best solutions below

0
Himani On

Adding PRIMARY KEY (id) at last resolved the error

private function runDbMigration_20() {
    $sql = "CREATE TABLE " . WSWEB_DB_TABLE_PREFIX . "subscribers (
    id int(11) UNSIGNED AUTO_INCREMENT,     
    name tinytext NOT NULL,
    email text NOT NULL,
            secretkey text NOT NULL,
            random_key text NOT NULL,
            onehourmailsent int(1) NOT NULL DEFAULT 0,
            onedaymailsent int(1) NOT NULL DEFAULT 0,
            wbstartingmailsent int(1) NOT NULL DEFAULT 0,
            replaymailsent int(1) NOT NULL DEFAULT 0,
    temp_id int(11) NOT NULL,
            exact_time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
            watch_day varchar(3),
            watch_time time,
            time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
            last_seen datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
            active int(1) UNSIGNED NOT NULL DEFAULT 1,
            high_five int(1) UNSIGNED NOT NULL DEFAULT 0,
            attended int(1) UNSIGNED NOT NULL DEFAULT 0,
            PRIMARY KEY  (id)
)" . $this->CHARSET_COLLATE . ";";
    return $this->calldbDelta($sql);
}