我有三个表:倡导者、客户和事件。在事件表中,我有两个字段引用倡导者表中的两个字段和一个引用客户端的字段,当我尝试添加外键时,我收到无法添加外键约束错误。
create table advocate(
ida int(11) not null,
idk int(11) not null,
#...
primary key(ida, idk)
)engine = InnoDB default charset=utf8;
create table client(
jmb varchar(13) not null primary key
#...
)engine=InnoDB default charset=utf8;
create table event(
ida int(11) not null,
idk int(11) not null,
jmb varchar(13) not null,
#...
primary key(ida,idk,jmb),
foreign key(ida, idk)
references advocate(ida, idk)
on update cascade
on delete restrict,
foreign key(jmb)
references client.jmb
on update cascade
on delete restrict
)engine=InnoDB default charset=utf8;
最佳答案
你可以尝试改变:
foreign key(jmb)
references client.jmb
on update cascade
on delete restrict
至
foreign key(jmb)
references client (jmb)
on update cascade
on delete restrict
关于mysql - 无法添加外键约束,mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42330221/