现在,在将其标记为重复之前,我经历了许多堆栈溢出解决方案。

名称匹配

数据类型匹配

两者都不为空,

可能是什么问题呢?

这是我的代码:

create database Registration;
use Registration;

create table Department(DepartmentID varchar(25) NOT NULL, DepartmentName varchar(25),
PRIMARY KEY(DepartmentID));
insert into Department(DepartmentID, DepartmentName) values ('DE1', 'Engligh');
insert into Department(DepartmentID, DepartmentName) values ('DS2', 'Science');
insert into Department(DepartmentID, DepartmentName) values ('DM3', 'Math');

create table Course(CourseID varchar(25), CourseName varchar(25), DepartmentID varchar(25) NOT NULL,
PRIMARY KEY (CourseID),
FOREIGN KEY(DepartmentID) REFERENCES Departmnet(DepartmentID));

最佳答案

create table Course(CourseID varchar(25), CourseName varchar(25),  DepartmentID varchar(25) NOT NULL,
PRIMARY KEY (CourseID),
FOREIGN KEY(DepartmentID) REFERENCES Department(DepartmentID));


您在参考表名称DEPARTMENT中犯了拼写错误

关于mysql - MYSQL工作台-错误1215:无法添加外键约束,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47455956/

10-12 02:02