Plugin won't create table..
-
Hi, I am new to plugin development, I am having trouble getting my plugin to automatically create my table.. can anyone see in my code why it won’t work? If i run the query in phpMyAdmin (obviously replacing the variables with actual values) it seems to work… so i’m guessing it’s just the wpdb function doesn’t like it.
The plugin activates without errors.
$table_name = $wpdb->prefix . "fb_events"; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id int(9) NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, slug varchar(255) NOT NULL, details text NOT NULL, location varchar(255) NOT NULL, start_date date NOT NULL, end_date date NULL, start_time varchar(255) NOT NULL, end_time varchar(255) NULL, image varchar(255) NOT NULL, comments int(1) DEFAULT '1', approved int(1) DEFAULT '0', user_id int(11) NOT NULL, created_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', updated_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id), UNIQUE KEY slug (slug) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql);
The topic ‘Plugin won't create table..’ is closed to new replies.