Mysql,无法添加外键约束
为什么会这样:Mysql,无法添加外键约束,mysql,Mysql,为什么会这样: Create table Kaart ( aantal_geel int not null, aantal_rood int not null, Primary key (aantal_geel, aantal_rood)); Create table Wedstrijd ( datum date not null, aantal_geel int not null, aantal
Create table Kaart (
aantal_geel int not null,
aantal_rood int not null,
Primary key (aantal_geel, aantal_rood));
Create table Wedstrijd (
datum date not null,
aantal_geel int not null,
aantal_rood int not null,
Primary key (datum),
Foreign key (aantal_geel) REFERENCES kaart(aantal_geel),
Foreign key (aantal_rood) REFERENCES kaart(aantal_rood));
给出:错误代码:1215。无法添加外键约束您需要引用键列的组合,而不是单独引用每个键列:
Create table Wedstrijd
(
datum date not null,
aantal_geel int not null,
aantal_rood int not null,
Primary key (datum),
Foreign key (aantal_geel,aantal_rood)
REFERENCES kaart(aantal_geel,aantal_rood)
);
我想这实际上不起作用。Mysql没有在对象浏览器信息中加粗“aantal_rood”。因此,只有aantal_geel被设置为外键。但它没有给出任何错误。这是Mysql中的一个bug还是根本不起作用?@user2214897:对我来说有效:我不知道对象浏览器中的“粗体”是什么,但似乎这个“对象浏览器”是错误的。您使用的是哪个MySQL版本?@user2214897:那么这似乎是MySQL工作台中的一个“bug”。我的工具清楚地显示了PK和FK约束。顺便说一句:据我所知,J.W.解决方案是错误的(请参阅我的评论和SQLFIDLE来证明)