我想創建一系列具有多個外鍵關係的表。兩個表中的第一個有兩列主鍵,一次由我們指定,另一個由製造商指定。當嘗試第三個查詢時發生該錯誤。我不確定這裏出了什麼問題,所以任何幫助都會受到真誠的讚賞。MySQL錯誤150(外鍵問題?)
SQL
CREATE TABLE rugs (
id INTEGER NOT NULL AUTO_INCREMENT,
manufacturer_id INTEGER NOT NULL,
name VARCHAR(255),
description TEXT,
PRIMARY KEY (id, manufacturer_id)
);
CREATE TABLE carpets (
id INTEGER NOT NULL AUTO_INCREMENT,
manufacturer_id INTEGER NOT NULL,
name VARCHAR(255),
warranty TEXT,
description TEXT,
fiber_name VARCHAR(255),
brand_name VARCHAR(255),
texture_name VARCHAR(255),
PRIMARY KEY (id, manufacturer_id)
);
CREATE TABLE carpet_styles (
id INTEGER NOT NULL AUTO_INCREMENT,
carpet_id INTEGER,
style_name VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (carpet_id) REFERENCES carpets (manufacturer_id)
);
CREATE TABLE carpet_colors (
id INTEGER NOT NULL AUTO_INCREMENT,
carpet_id INTEGER,
color_name VARCHAR(255),
color_category VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (carpet_id) REFERENCES carpets (manufacturer_id)
);
CREATE TABLE carpet_custom_names (
id INTEGER NOT NULL AUTO_INCREMENT,
carpet_id INTEGER,
custom_name VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (carpet_id) REFERENCES carpets (manufacturer_id)
);
CREATE TABLE rug_styles (
id INTEGER NOT NULL AUTO_INCREMENT,
rug_id INTEGER,
style_name VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (rug_id) REFERENCES rugs (manufacturer_id)
);
CREATE TABLE rug_colors (
id INTEGER NOT NULL AUTO_INCREMENT,
rug_id INTEGER,
color_name VARCHAR(255),
color_category VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (rug_id) REFERENCES rugs (manufacturer_id)
);
CREATE TABLE rug_shapes (
id INTEGER NOT NULL AUTO_INCREMENT,
rug_id INTEGER,
shape_name VARCHAR(255),
shape_category VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (rug_id) REFERENCES rugs (manufacturer_id)
);
CREATE TABLE catalog_contents (
id INTEGER NOT NULL AUTO_INCREMENT,
catalog_id INTEGER,
carpet_id INTEGER,
rug_id INTEGER,
PRIMARY KEY (id),
FOREIGN KEY (rug_id) REFERENCES rugs (id),
FOREIGN KEY (carpet_id) REFERENCES carpets (id),
FOREIGN KEY (catalog_id) REFERENCES catalogs (id)
);
'顯示的InnoDB status'真正將傾一噸的信息,並在所有的中間,這將是一個「最後的外鍵錯誤」部分,用的究竟是什麼導致了更多的細節你得到的150個代碼。 –
不幸的是,這不再是一個與最新版本的MySQL的選項(意思是我在發佈問題到stackoverflow.com之前試過這個) – bulletshot60