我有以下父表:复合外键
create table A(
a int(64) unsigned not null,
b set('a', 'b', 'c') not null default '',
c set('d', 'e') not null default '',
primary key (a,b,c)
)
而且孩子:
create table B(
d int(64) unsigned not null auto_increment,
a int(64) unsigned not null,
c set('d', 'e') not null default '',
primary key (d),
key fk1 (a,c),
constraint fk1 foreign key (a, c) references (a, c)
)
但后来我得到一个FK错误上创建mysql日志中的子表:
表的外键约束出错外键(a,c)引用 A(a,c):无法找到引用表中 引用列显示为第一列的索引,或 表中的列类型与被引用表的约束不匹配。
我的SQL有什么不正确?
围绕列名称有单引号。我认为这是一个错字,并投票结束这些问题。 –
@GordonLinoff不,我不认为这是一个错字。 Ty用于格式化 – user1561108
1.引用的表名缺失。 2.所引用的表格上没有可以支持FK的索引。 3.在相同的列上引用没有唯一索引的列(对于引用的表)是一种奇怪的设计。 –