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 :)