I have a table that represents a tree:
CREATE table entries
(id INT unsigned primary key,
name VARCHAR(30) NOT NULL,
parent_id INT unsigned,
foreign key (parent_id) references
entries(id) ON UPDATE CASCADE ON DELETE CASCADE);
When I try to delete some entry by id with childs then everything works fine, but when I try to update id, I get error:
Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails
(`db`.`entries`, CONSTRAINT `name2_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `entries` (`id`) ON
DELETE CASCADE ON UPDATE CASCADE)