最佳答案
为什么mygroup
上的截断不起作用?虽然我有ON DELETE CASCADE SET
我得到:
错误1701(42000):无法截断外键约束中引用的表(
mytest
.instance
, CONSTRAINTinstance_ibfk_1
FOREIGN KEY(GroupID
)REFERENCESmytest
.mygroup
(ID
))
drop database mytest;create database mytest;use mytest;
CREATE TABLE mygroup (ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE instance (ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,GroupID INT NOT NULL,DateTime DATETIME DEFAULT NULL,
FOREIGN KEY (GroupID) REFERENCES mygroup(ID) ON DELETE CASCADE,UNIQUE(GroupID)) ENGINE=InnoDB;