similar to ON DELETE CASCADE not working in MySQL, but something is not right:
-- test delet
If you create t2 like this it works fine:
CREATE TABLE `t2` (
`id` bigint(20) unsigned NOT NULL,
`data2` text,
PRIMARY KEY (`id`),
CONSTRAINT `FK_t2_1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ETA, in answer to concerns about ugly code, the below also works:
CREATE TABLE t2 (
id bigint(20) unsigned NOT NULL PRIMARY KEY,
data2 text,
CONSTRAINT FOREIGN KEY (id) REFERENCES t1(id) ON DELETE CASCADE
) ENGINE=InnoDB ;
The main difference is that the data type for t2.id must match that of t1.id and constraints have to be declared after the columns.