LMSouq
database Open

How to truncate a foreign key constrained table?

US
user391986
1 month ago
3 views
Problem Description
Why doesn't a **TRUNCATE** on `mygroup` work? Even though I have `ON DELETE CASCADE SET` I get: >ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (`mytest`.`instance`, CONSTRAINT `instance_ibfk_1` FOREIGN KEY (`GroupID`) REFERENCES `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;

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base