首先感謝您的幫助和支持的話。 當我從網上學習MySQL時,我知道我會犯很多錯誤,並提前感謝您的耐心和理解。無法創建表'basque30.newreferral'(errno:150)
我正在創建基於Java的項目,然後創建一個MySQL數據庫和表。 一般來說,它很順利,直到我遇到這個問題。迄今爲止,它給了我最大的麻煩。我讀了很多關於錯誤150的文章。我讀過error 150 on MySQL site,我認爲我已經完成了錯誤150發生的十個原因。
我正在調用的調用是創建每個表。以下是一些覆蓋我遇到的問題的表格。
這是WorkCalendar表
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)"
+ ")";
這是NewReferral表
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)"
+ ")";
該錯誤是無法創建表「basque30.newreferral」(錯誤:150)
我已經跟蹤誤差降低到以下行
+ "FOREIGN KEY(SpecIdNo) REFERENCES Specialist(SpecIdNo),"
有人能指出錯誤我的方式,並告訴我如何解決它。
您是按照此處列出的順序創建表格嗎? – Mihai
感謝Mihai,在他們被調用的方法中,我讓他們倒過來了。我的錯。如果您可以創建回覆,我會很樂意將其作爲正確的解決方案。 –