首先建立user表,如下图

Navicat MYSQL 建立关联表 保存时遇到 cannot add foreign key constraint

 

 然后建立message表,userid用作外键,关联user表的id

Navicat MYSQL 建立关联表 保存时遇到 cannot add foreign key constraint

 

 点击上面的外键按钮,添加外键如下

Navicat MYSQL 建立关联表 保存时遇到 cannot add foreign key constraint

 

 结果保存时报错: cannot add foreign key constraint

Navicat MYSQL 建立关联表 保存时遇到 cannot add foreign key constraint

 

 最后查找发现user表中的id和message表中的userid定义的属性不一样,如下,一个选择了无符号,一个没选,两个选一样的,按照上面添加外键的方法就解决问题了:

Navicat MYSQL 建立关联表 保存时遇到 cannot add foreign key constraintNavicat MYSQL 建立关联表 保存时遇到 cannot add foreign key constraint

 

相关文章: