将多个键引用到MYSQL表的单个列中 [英] Referencing multiple keys into a single column in MYSQL table

查看:142
本文介绍了将多个键引用到MYSQL表的单个列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个表列需要映射与两个表的主键的关系.这两个键应与外键同一个列相关.在MY SQL中是可能的.在下面.

错误1452:无法添加或更新子行:外键约束失败.

请帮助我纠正这个问题

我尝试过的事情:

Hi,
I have a table column which needs to map the relation with the primary keys of two tables.The two keys should be related to the same column as foreign keys.Is this possible in MY SQL.When I am doing so it is throwing the error below.

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

Please help me to rectify this one

What I have tried:

I have a table column which needs to map the relation with the primary keys of two tables.The two keys should be related to the same column as foreign keys.

推荐答案

这种关系很好.该错误是由于外键约束"引起的,您不能插入或更新外键值,除非该外键值首先存在于它所引用的主键表中.
详细了解 SQL FOREIGN KEY约束 [
The relationship is fine. The error comes about because of the "foreign key constraint", you cannot insert or update a foreign key value without it first exists in the primary key table(s) that it references.
Learn more about SQL FOREIGN KEY Constraint[^]


这篇关于将多个键引用到MYSQL表的单个列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆