ERROR 1215 (HY000): Cannot add foreign key constraint

alter table 表名字 add constraint fk_当前表_关联表 foreign key(列) references 另一个表(列);

添加外键约束时报错,原因是两张表的字符集不一致,

查看字符集show create table 表名;

到这里问题还没得到解决,发现,列的字符集也不一样

查看所有字段字符集:

SHOW FULL COLUMNS FROM tbl_name

修改字段字符编码:

alter table tab_name change 列 列 类型(长度) character set utf8;

 

posted on 2020-12-03 17:41  刀锋93  阅读(226)  评论(0编辑  收藏  举报

导航