I’m using following install function with dbDelta as referring to the codex, articles on SO I watched out for the typical problems with e.g. one space instead of two spaced at the PRIMARY KEY …

function myplugin_install(){
    global $wpdb;
    $table_name = $wpdb->prefix . "vehicles";       

    $sql = "CREATE TABLE IF NOT EXISTS $table_name 
    (
        id                  INT UNSIGNED NOT NULL AUTO_INCREMENT,
        description         VARCHAR(25) NOT NULL,
        PRIMARY KEY  (id)
    );  
    ";

    $sql .= "CREATE TABLE IF NOT EXISTS $table_name1 
    (
        ...
    )";

    $sql .= "CREATE TABLE IF NOT EXISTS $table_nameX 
    (
        id                  INT UNSIGNED NOT NULL AUTO_INCREMENT ,
        art_alarmierung     VARCHAR(25) NOT NULL ,
        PRIMARY KEY  (id)
    );";

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

}

dbDelata only stores the last $sql variable. And echo $wpdb->last_error; don’t show any errors?
Where is my failure?

BR;
mybecks

2 s
2

Run dbDelta for each SQL statement seperately:

function myplugin_install(){
    global $wpdb;
    $table_name = $wpdb->prefix . "vehicles";       
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

    $sql = "CREATE TABLE IF NOT EXISTS $table_name 
    (
        id                  INT UNSIGNED NOT NULL AUTO_INCREMENT,
        description         VARCHAR(25) NOT NULL,
        PRIMARY KEY  (id)
    );  
    ";
    dbDelta($sql);

    $sql2 = "CREATE TABLE IF NOT EXISTS $table_name1 
    (
        ...
    )";
    dbDelta($sql2);

    $sql3 = "CREATE TABLE IF NOT EXISTS $table_nameX 
    (
        id                  INT UNSIGNED NOT NULL AUTO_INCREMENT ,
        art_alarmierung     VARCHAR(25) NOT NULL ,
        PRIMARY KEY  (id)
    );";

    dbDelta($sql3);

}

Leave a Reply

Your email address will not be published. Required fields are marked *