0

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)
crends
  • 65
  • 4
  • Can you add sample data and the query? Maybe make a sqlfiddle. – Barmar Aug 16 '21 at 21:24
  • Just something like `INSERT INTO entries VALUES (1, "word", NULL), (2, "tratata", 1);` is enough, can't change id from 1 to anything else. – crends Aug 16 '21 at 21:29

0 Answers0