創建觸發器成功MySQL的觸發器不能援引
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
有人能指出我做了什麼錯?感謝
它給了我之前同樣的錯誤 – jctank
insted的後添加 – shola
你有沒有試過以上? – shola