Failed to add the foreign key constraint. Missing index for constraint 'stu_ibfk_1' in the reference

alter table stu add foreign key(cno) references user(id);

Failed to add the foreign key constraint. Missing index for constraint 'stu_ibfk_1' in the referenced table 'user'

解决方案:

作为外键,user表中的id必须是唯一值,因此得添加约束unique,或者primary key;

posted @ 2021-09-26 13:22  *乐途*  阅读(1425)  评论(0)    收藏  举报