我的 MySQL 数据库中有两个表Event
和Theme
.
ALTER TABLE Event ADD CONSTRAINT FK_FA6F25A359027487 FOREIGN KEY (theme_id) REFERENCES Theme (_uuid) ON DELETE SET NULL;
ALTER TABLE Theme ADD CONSTRAINT FK_56B4C80C71F7E88B FOREIGN KEY (event_id) REFERENCES Event (_uuid) ON DELETE CASCADE;
我想要这样的行为,如果我删除主题记录,theme_id 设置为 NULL,如果我删除事件记录,主题记录也被删除。
但是,现在当我运行 DELETE FROM Event 时,我收到此错误。
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`from_dev`.`eventleveltheme`, CONSTRAINT `FK_6E25E16871F7E88B` FOREIGN KEY (`event_id`) REFERENCES `Event` (`_uuid`))
我不能同时设置这两个约束吗?它们是否以某种方式发生冲突?