I've been trying to figure this one out for 3 days now, reading every reference on dbDelta I can find.
My ultimate goal is to create a table of unique ad_id, ad_trigger pairs.
This does not create a table:
if($wpdb->get_var("SHOW TABLES LIKE '$ad_trigger_table_name'") != $ad_trigger_table_name) {
$sql = "CREATE TABLE " . $ad_trigger_table_name . " (
ad_id int(12) NOT NULL,
ad_trigger text NOT NULL,
PRIMARY KEY (ad_id,ad_trigger)
);";
dbDelta($sql);
}
Nor does this:
$sql = "CREATE TABLE " . $ad_trigger_table_name . " (
ad_id int(12) NOT NULL,
ad_trigger text NOT NULL,
UNIQUE KEY pkey (ad_id,ad_trigger)
);";
dbDelta($sql);
This does work -- but does not give me a composite key.
if($wpdb->get_var("SHOW TABLES LIKE '$ad_trigger_table_name'") != $ad_trigger_table_name) {
$sql = "CREATE TABLE " . $ad_trigger_table_name . " (
id int(12) NOT NULL auto_increment,
ad_id int(12) NOT NULL,
ad_trigger text NOT NULL,
PRIMARY KEY (id)
);";
dbDelta($sql);
}
Any light anyone can shed on this would be great!
unsigned
(positive only) numeric values only. How would you determine a key that consists out of two different types? Also: Are you really, really, really sure you need composite keys? I want to question that. But please just file an edit and explain us what you are trying to do (not only "I want a table", but the full story). It could be that you are facing a XY Problem.CONSTRAINT constraint_name UNIQUE ( column_one, column_two )
, then you could makeconstraint_name
your primary key. Or something along that line at least.