mercredi 18 mai 2016

Wordpress Plugin Create Database Table

Trying to create a pair of database tables within my table. Below is the code block that is being executed on the activation of my plugin. Wordpress reports that it's successful, however when refreshing the database the employee table is being created.

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

    // create the database table.        
    global $wpdb;
    $charset_collate = $wpdb->get_charset_collate();

    $table_name = $wpdb->prefix . "fengate_department";
    $table_name2 = $wpdb->prefix . "fengate_employee";

    $sql = "CREATE TABLE $table_name (
        id INT(11) NOT NULL AUTO_INCREMENT,   
        name VARCHAR(255) NOT NULL,
        PRIMARY  KEY (id)
        ) $charset_collate;";

     $sql2 = "CREATE TABLE $table_name2 (
        id INT(11) NOT NULL AUTO_INCREMENT,     
        first_name VARCHAR(255) NOT NULL,
        last_name VARCHAR(255) NOT NULL,
        department_id INT(11) NOT NULL,
        PRIMARY  KEY (id),
        CONSTRAINT department_id
        FOREIGN KEY (id)
        REFERENCES fengate_department (id)
        ON DELETE NO ACTION
        ON UPDATE NO ACTION);
        ) $charset_collate;";                

    dbDelta($sql);        
    dbDelta($sql2);        

Ideas on how to resolve would be greatly appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire