2014-03-14 148 views
0

我正在做一項任務,並遇到了一個錯誤,使得其中一個外鍵失效。無法創建2個外鍵,「errno:150」

第一個表:

CREATE TABLE MANUFACTURERS 
(
Manufacturers_ID int(5) UNIQUE, 
Name varchar(15) UNIQUE, 
City varchar(30), 
State char(2), 
Zip char(5), 
Phone char(10), 
PRIMARY KEY (Manufacturers_ID) 
) 
ENGINE= innodb; 

二表

CREATE TABLE OWNERS 
(
Owner_ID int(10), 
First_Name varchar(15), 
Last_Name varchar(15), 
City varchar(30), 
State char(2), 
Gender varchar(1), 
Date_of_Birth varchar(10), 
PRIMARY KEY (Owner_ID) 
) 
ENGINE= innodb; 

三表

CREATE TABLE CARS 
(
Vehicle_Identification_Number int(17) NOT NULL UNIQUE, 
Manufacturers_ID int(5) UNIQUE, 
Owner_ID int(10) UNIQUE, 
Model varchar(25), 
Manufaturer_Year int(4), 
Mileage int(10), 
Price int(10), 
PRIMARY KEY (Vehicle_Identification_Number), 
FOREIGN KEY (Manufacturers_ID) REFERENCES MANUFACTURERS (Manufactures_ID), 
FOREIGN KEY (Owner_ID) REFERENCES OWNERS (Owner_ID) 
) 
ENGINE= innodb; 

當我嘗試執行第三個表,我得到的消息:

「錯誤已經發生在執行你的SQL命令時執行。

錯誤:無法創建表「ds0004.CARS」(錯誤:150)。」

任何幫助,將不勝感激

+0

http://stackoverflow.com/questions/4061293/mysql-cant-create-table-errno-150 – Zoxac

回答

1

您在CARS拼錯了國外參考這是正確的版本:

CREATE TABLE CARS 
(
Vehicle_Identification_Number int(17) NOT NULL UNIQUE, 
Manufacturers_ID int(5) , 
Owner_ID int(10) , 
Model varchar(25), 
Manufaturer_Year int(4), 
Mileage int(10), 
Price int(10), 
PRIMARY KEY (Vehicle_Identification_Number), 
FOREIGN KEY (Manufacturers_ID) REFERENCES MANUFACTURERS (Manufacturers_ID), 
--------------------------------------------------------------------^ 
FOREIGN KEY (Owner_ID) REFERENCES OWNERS (Owner_ID) 
) 
+0

的可能重複謝謝你,我的工作可能會從來沒有發現這個錯誤。 – KingDave212

相關問題