0

I am working on creating a table in the DB for a plugin but cannot figure out why the table is not being created.

Here's my code:

global $ds_swoons_db_version;
$ds_swoons_db_version = '1.0';

function ds_swoons_install(){
global $wpdb;

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

if( $wpdb->get_var("show tables like '$table_name'") != $table_name ):
    $sql = "CREATE TABLE IF NOT EXISTS " . $table_name . " (
            id mediumint(9) NOT NULL AUTO_INCREMENT,
            post_id int(9) NOT NULL,
            user_id (9) NOT NULL,
            swoon_status int(1),
            UNIQUE KEY id (id)
            );";
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    //make the query
    dbDelta($sql);
    //add db verison number
    add_option('ds_swoons_db_version', $ds_swoons_db_version);
endif;

}//end ds_swoons_install

register_activation_hook( __FILE__, 'ds_swoons_install');

I tried to echo the error but get an unexpected output error - probably due to headers being sent already. This is all the code I have so far - just wanted to see if I could create the table before moving on to anything else.

Thanx in advance!

EDIT ----------------------------------------------------

I figured it out - I did not have the data type declaration for user_id so it never created the table. I changed it and it worked :)

2
  • You should post your answer as an answer rather than in your question. It just helps the community read easier. Commented Oct 16, 2011 at 3:36
  • Hi, thanks for the heads up. I answered the question for clarity.
    – dkmojo
    Commented Oct 16, 2011 at 23:54

1 Answer 1

1

I figured it out - I did not have the data type declaration for user_id so it never created the table. I changed it and it worked :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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