0

I'm trying to have a foreign key (parent_id) and a primary key (id) in an already existing table.

I already used SET FOREIGN_KEY_CHECKS=0; and then I ran this query below but every time I get the same error.

ALTER TABLE categories
ADD CONSTRAINT fk_parent_id FOREIGN KEY ( parent_id ) REFERENCES 
categories(id) on DELETE CASCADE

Cannot add or update a child row: a foreign key constraint fails

  • Possible duplicate of [Cannot add or update a child row: a foreign key constraint fails](https://stackoverflow.com/questions/5005388/cannot-add-or-update-a-child-row-a-foreign-key-constraint-fails) – Moses Schwartz Aug 05 '19 at 00:19
  • what do you want to accomplish with building a foreign key on the same table? – nbk Aug 05 '19 at 00:30

0 Answers0