为什么没有一个TRUNCATE上mygroup
工作?即使ON DELETE CASCADE SET
我知道了:
错误1701(42000):无法截断在外键约束中引用的表(
mytest
。instance
,CONSTRAINTinstance_ibfk_1
FOREIGN KEY(GroupID
)参考mytest
。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;