我在mysqldump 5.5.36中遇到了一个问题,其中没有强制执行外键约束,也没有使用MariaDB导出外键约束。我的进一步调查显示,这些键在"SHOW CREATE TABLE“中没有显示,甚至没有强制执行。我确信我的DDL出了什么问题,但是找不出来。
我使用常规的mysql CLI测试了以下内容。
DDL:
create table parent(id bigint auto_increment not null,
name varchar(32),
primary key (id));
create table child(id bigint auto_increment not null,
parent_id bigint, name varchar(32),
primary key (id),
foreign key fk_parent_id (parent_id) references parent(id) ON DELETE CASCADE);DML:
insert into parent(name) values('P1');
insert into child(parent_id, name) values(1, 'C1');
DELETE from parent;
DROP table parent;我预计DELETE或DROP语句会导致错误,但它没有,并且子表仍然包含一行。此外,在本测试中,mysqldump或"show create table child“都没有显示外键"ON DELETE CASCADE”部分。
对此有什么想法吗?
发布于 2014-05-15 10:21:28
正如Michael Berkowski所指出的,问题出在MyISAM存储引擎上。将其更改为InnoDB解决了此问题。
https://stackoverflow.com/questions/23667908
复制相似问题