Plugin not creating table on activation.
-
Greetings,
I’m developing my first plugin, but am running into issues with the plugin not creating the table in my database, when I initialize it. I know that its being called, because the option is added into my wp_options folder. I’m baffled as to why this isn’t working, so your help is very much appreciated.
The method is below:
// Activate Plugin
register_activation_hook(__FILE__,’init_database’);function init_database() {
global $wpdb, $table_prefix;
global $favoritethis_db_version;
$table_name = $table_prefix.”favorites”;if ($wpdb->get_var(“show tables like ‘$table_name'”) != $table_name) {
require_once(ABSPATH . ‘wp-admin/upgrade-functions.php’);
dbDelta(“CREATE TABLE” . $table_name . ” (
id
mediumint(9) NOT NULL AUTO_INCREMENT,
post_id
mediumint(9) NOT NULL default ‘0’,
PRIMARY KEY (id
)
);”);add_option(“favoritethis_db_version”, “1.0”);
}
}
- The topic ‘Plugin not creating table on activation.’ is closed to new replies.