做数据库课程作业的时候,导入sql文件的时候遇到这个问题:
Cannot add foreign key constraint
mysql无法添加外键约束(cannot add foreign key constraint)
在网上查了半天,说是这种问题一般是两个数据类型或者数据精度不一致导致的,但是自己这些都没问题。。

创建表的代码如下(部分)
mysql无法添加外键约束(cannot add foreign key constraint)
show tables发现只有三个表创建成功,带有foreign key的全都不行。。
mysql无法添加外键约束(cannot add foreign key constraint)
纠结半天。。
最后发现references department 后面加上(dept_name) department就可以创建了!!
mysql无法添加外键约束(cannot add foreign key constraint)

今天问了下老师,说是不同数据库管理系统之间语句可能有些不同。。
mysql在定义foreign key的时候需要在后面加上自己的主键。

相关文章:

  • 2021-11-22
  • 2021-10-13
  • 2022-12-23
  • 2021-04-05
  • 2022-12-23
  • 2022-01-09
  • 2021-06-06
  • 2022-12-23
猜你喜欢
  • 2021-05-04
  • 2021-11-24
  • 2022-12-23
  • 2021-07-28
  • 2021-08-06
  • 2021-04-11
  • 2022-12-23
相关资源
相似解决方案