一个表中同一列上的两个外键 [英] Two foreign keys on the same column from one table
本文介绍了一个表中同一列上的两个外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个项目表,其中有一个image_id
字段和一个newsimage_id
字段.
i have a project table which has a image_id
field and a newsimage_id
field.
两者都链接到图像表.但是InnoDB不允许我为
两个字段都放在同一列(id
).
Both are linked to the image table. But InnoDB doesn't allow me to set a foreign key for
both fields to the same column (id
).
有没有办法可以做到这一点? 我正在通过MAMP使用MySQL.
Is there a way I can do this or is it not possible? I'm using MySQL through MAMP.
提前谢谢!
推荐答案
这是我的操作方式(MySQL 5.0.45):
Here's how I did it (MySQL 5.0.45):
ALTER TABLE `job_dependency`
ADD FOREIGN KEY (`job`) REFERENCES `job` (`id`),
ADD FOREIGN KEY (`dependency`) REFERENCES `job` (`id`);
在这种情况下,ON DELETE CASCADE存在问题,请不要使用它.
There are problems with ON DELETE CASCADE in this situation, so don't use it.
这篇关于一个表中同一列上的两个外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文