About mysql reporting an error when adding a foreign key_MySQL reporting an error when adding a foreign key: 1215 Cannot add the foreign key constraint A possible solution...

今天给设计好的班级表和专业表以及院系表添加外键时,报了这样一个错误 **

1215 Cannot add the foreign key constraint

**
insert image description here
Go to Baidu to search for a circle, and said that it may be caused by inconsistent field types and lengths. I checked the corresponding data table and found that the corresponding field data type length is consistent with the data data engine type, so this is not the problem.

又去仔细找了一圈,发现了一个问题,发现喔设置外键的两张表排序规则不一样,哈哈哈,这个马虎眼打得

insert image description here
insert image description here
One is utf8-unicode_ci, the other is utf8-general_ci, as expected, the problem lies in this, it is OK to change to the same sorting rules

titleinsert image description here

Guess you like

Origin blog.csdn.net/qq_46034741/article/details/124971150
Recommended