Just trying to create a new database table on plugin activation. For the love of life I cannot figure out why this will not work.
function super_simple_photo_activate() {
global $wpdb;
$table_name = $wpdb->prefix."super_simple_photo_options";
if ($wpdb->get_var('SHOW TABLES LIKE '.$table_name) != $table_name) {
$sql = 'CREATE TABLE '.$table_name.'(
thumbs_max VARCHAR(3),
image_max VARCHAR(4),
image_quality VARCHAR(3),
PRIMARY KEY (id))';
require_once(ABSPATH.'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("super_simple_photo_db_version", "1.0");
}
}
register_activation_hook(__FILE__, 'super_simple_photo_activate');
I've spent at least 5 hours tinkering with this but with no luck, no error either on activation.
What did the trick - id INTEGER NOT NULL - thanks t.thielemans
$sql = 'CREATE TABLE '.$table_name.'(
id INTEGER NOT NULL,
thumbs_max VARCHAR(3),
image_max VARCHAR(4),
image_quality VARCHAR(3),
PRIMARY KEY (id))';
Your create table syntax is wrong, should be:
Edit: Define your primary key
Bit of extra info on SQL from W3schools: http://www.w3schools.com/sql/sql_primarykey.asp
Try this code