首先感谢您的帮助和支持的话。当我从网上学习 MySQL 时,我知道我会犯很多错误,并提前感谢您的耐心和理解。
我正在制作基于 Java 的项目,然后创建一个 MySQL 数据库和表。通常它进展顺利,直到我遇到这个问题。到目前为止,它给了我最大的头痛。我阅读了很多关于错误 150 的文章。我在 MySQL 网站上阅读了错误 150,我认为我已经满足了发生错误 150 的十个原因。
我正在调用的是创建每个表。以下是一些涵盖我遇到的问题的表格。
这是工作日历表
private String workCalandar = "CREATE TABLE WorkCalendar ("
+ "WorkCalendarIdNo INT(64) NOT NULL AUTO_INCREMENT,"
+ "WorkCalendarDate Date,"
+ "WorkCalendarDayCount INT(64),"
+ "WorkDayTypeIdNo INT(64),"
+ "PRIMARY KEY(WorkCalendarIdNo),"
+ "FOREIGN KEY(WorkDayTypeIdNo) REFERENCES WorkDayType(WorkDayTypeIdNo)"
+ ")";
这是部门表
private String department = "CREATE TABLE Department ("
+ "DeptIdNo INT(64) NOT NULL AUTO_INCREMENT,"
+ "DeptName VARCHAR(25),"
+ "PRIMARY KEY(DeptIdNo)"
+ ")";
这是专家表
private String specialist = "CREATE TABLE Specialist ("
+ "SpecIdNo INT(64) NOT NULL AUTO_INCREMENT,"
+ "PrefixIdNo INT(64),"
+ "SpecFirstName VARCHAR(30),"
+ "SpecSurname VARCHAR(35),"
+ "SpecDisplayName VARCHAR(72),"
+ "DeptIdNo INT(64),"
+ "PRIMARY KEY(SpecIdNo),"
+ "FOREIGN KEY(PrefixIdNo) REFERENCES Prefix(PrefixIdNo),"
+ "FOREIGN KEY(DeptIdNo) REFERENCES Department(DeptIdNo)"
+ ")";
这是新推荐表
private String newReferral = "CREATE TABLE NewReferral("
+ "NewReferralIdNo INT(64) NOT NULL AUTO_INCREMENT,"
+ "PatientNumber VARCHAR(12),"
+ "NewReferralDate Date,"
+ "DeptIdNo INT(64),"
+ "SpecIdNo INT(64),"
+ "NewReferralMatched BOOLEAN,"
+ "WorkCalendarIdNo INT(64),"
+ "PRIMARY KEY(NewReferralIdNo),"
+ "FOREIGN KEY(DeptIdNo) REFERENCES Department(DeptIdNo),"
+ "FOREIGN KEY(SpecIdNo) REFERENCES Specialist(SpecIdNo),"
+ "FOREIGN KEY(WorkCalendarIdNo) REFERENCES WorkCalendar(WorkCalendarIdNo)"
+ ")";
错误是 Can't create table 'basque30.newreferral' (errno: 150)
我已将错误跟踪到以下行
+ "FOREIGN KEY(SpecIdNo) REFERENCES Specialist(SpecIdNo),"
有人可以指出我的方法的错误并建议我如何解决它。