我在mysql代码中遇到问题。不允许我导入sql文件并给我这个错误" #1215 - 无法添加外键约束"
我不知道该怎么做。我在这里搜索过,我尝试了一些这样的例子:MySQL error: Cannot add foreign key constraint?但没有成功。
答案 0 :(得分:1)
您需要使用FK引用中的所有主键列。
FOREIGN KEY (`an`)
REFERENCES `studenti` (`an`)
应该是
FOREIGN KEY (`idstud`, `an`)
REFERENCES `studenti` (`idstud`,`an`)
当然,您需要将idstud
添加到teste
表格中。