Creating a trigger is successful
mysqli_query($this->conn,
"CREATE TRIGGER `before_delete_address`
BEFORE DELETE ON address FOR EACH ROW
DELETE FROM city WHERE cityid = OLD.cityid");
but when I execute the following query
DELETE FROM address WHERE addressid = 18
it outputs the following error code
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
The constraints on the address table are set to On Update cascade
and On Delete restrict
.
The columns of the address table are addressid, address, cityid, zipcode
, cityid is a FK reference to the city table contains cityid, city, countryid
Can someone point out what I have done wrong? thanks