Mysql约束无法添加

时间:2015-06-14 19:59:41

标签: mysql

我在mysql代码中遇到问题。不允许我导入sql文件并给我这个错误" #1215 - 无法添加外键约束"

我不知道该怎么做。我在这里搜索过,我尝试了一些这样的例子:MySQL error: Cannot add foreign key constraint?但没有成功。

1 个答案:

答案 0 :(得分:1)

您需要使用FK引用中的所有主键列。

FOREIGN KEY (`an`)
REFERENCES `studenti` (`an`) 

应该是

FOREIGN KEY (`idstud`, `an`)
REFERENCES `studenti` (`idstud`,`an`) 

当然,您需要将idstud添加到teste表格中。