Error adding ON DELETE CASCADE two Foreign Keys from the same table

Asked

Viewed 278 times

0

I am deploying a table to save the messages, in this table I have source users (sender) and destination user(recipient) from the same table: user.

When trying to add the constraints to the message table, I have the following error: The restriction introduction FOREIGN KEY FK_MOVMSGCHT_IDCUSRDST on the table MOVMSGCHT can cause cycles or multiple cascading paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other restrictions FOREIGN KEY.

Is there any way to use DELETE CASCADE in this case?

1 answer

0

Tries to reverse the order of delete, first the recipient and then the source, or vice versa.
Type

ALTER TABLE `origem`
ADD CONSTRAINT `destino_ibfk_1` FOREIGN KEY (`destino_id`) 
  REFERENCES `destino` (`destino_id`);

Or it goes the easy way, but that’s not a correct solution. Turn off the keycheck

SET FOREIGN_KEY_CHECKS=0; -- desliga
SET FOREIGN_KEY_CHECKS=1; -- religa

Browser other questions tagged

You are not signed in. Login or sign up in order to post.