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’

solution:

as the foreign key, user table id must be a unique value, so the constraint unique, or primary key must be added;

Read More: