简体   繁体   English

在组合键和外键之间创建关系

[英]Creating a relationship between a composite key and foreign key

I'm trying to link a foreign key to a composite key in mysql but im getting an error saying that the structure of the keys arent correct. 我正在尝试将外键链接到mysql中的复合键,但是我收到一条错误消息,说该键的结构不正确。 I've checked the datatype and character length and both are correct. 我检查了数据类型和字符长度,并且两者都是正确的。

Is this link even possible? 这个链接甚至可能吗? see below for image... 请参阅下面的图片...

Composite Key: 组合键: 在此处输入图片说明

Foreign Key: 外键: 在此处输入图片说明

Any help on this would be greatly appreciated. 任何帮助,将不胜感激。

Not possible to create foreign key from composite key. 无法通过组合键创建外键。 Should be refer from parent key is primary key and should be not of column in reference key also..as per your share screen not possible to create this.. If you want to achieve this business let me reply will give suggestion to you.. 应该从父键引用为主键,也不应在引用键的列中..根据您的共享屏幕,无法创建此键。.如果您想实现此业务,请让我答复。

I had my composite key the wrong way round. 我以错误的方式拿到了组合键。 I switched the 'UniqueCode' to act as the parent key and managed to link fine 我切换了“ UniqueCode”作为父键,并设法很好地链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM