I have the following code setup to create a table when the plugin is activated, but no table gets created.
Notes:
- When i copy the SQL direct to phpmyadmin it works
- The database user does have permission to create tables.
$scores_table_name = $wpdb->prefix . "scorepredictions";
$scores_db_version = "1.0";
function scores_install () {
global $wpdb;
global $scores_db_version;
global $scores_table_name;
if($wpdb->get_var("show tables like '$scores_table_name'") != $scores_table_name) {
$sql = "CREATE TABLE " . $scores_table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
post_id int NOT NULL,
user_id int NOT NULL,
home_team VARCHAR(255) NOT NULL,
away_team VARCHAR(255) NOT NULL,
home_score int NOT NULL,
away_score int NOT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("scores_db_version", $scores_db_version);
}
}
register_activation_hook(__FILE__,'scores_install');
Any ideas as to what i'm doing wrong?