创建触发器成功
mysqli_query($this->conn,
"CREATE TRIGGER `before_delete_address`
BEFORE DELETE ON address FOR EACH ROW
DELETE FROM city WHERE cityid = OLD.cityid");
但是当我执行以下查询时
DELETE FROM address WHERE addressid = 18
它输出以下错误代码
Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails (`gamecomp`.`address`, CONSTRAINT `cityid` FOREIGN KEY (`cityid`) REFERENCES `city` (`cityid`) ON UPDATE CASCADE) 0.039 sec
地址表的约束设置为On Update cascade
和On Delete restrict
。
地址表的列是addressid, address, cityid, zipcode
,cityid 是对包含的城市表的 FK 引用cityid, city, countryid
有人可以指出我做错了什么吗?谢谢