mysql - 无法添加外键约束,mysql

标签 mysql sql

我有三个表:倡导者、客户和事件。在事件表中,我有两个字段引用倡导者表中的两个字段和一个引用客户端的字段,当我尝试添加外键时,我收到无法添加外键约束错误。

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/

相关文章:

mysql - Node.js 异步嵌套 mysql 查询

mysql - 表左连接的组合到mysql中的内部连接

html - 如何在 SQL 中的字符串中实现字符串

mysql - 查找平均值的 SQL 查询

mysql - 在 PhpMyAdmin 中调用存储过程是可以的,但作为查询运行不起作用

javascript - 通过点击按钮获取一行的id和value

mysql - 创造性地使用 GROUP_CONCAT 来避免查询...可以检索记录组吗?

java - eclipse中struts2 mysql连接错误

c# - 如何在具有条件多个 where 条件的 Entity Framework 中编写查询?

sql - PostgreSQL 中两个日期之间的差异