我在为我的 salesorderslineitem 表构建架构时遇到问题。即使我尝试在小提琴中自行构建模式。我收到一条错误消息,无法添加外键约束...在这里,我的表一起试图让新的 salesorderslineitem 表正常工作。感谢大家!
CREATE TABLE salesorders
( donut_order_id INT(10) NOT NULL AUTO_INCREMENT,
customer_id INT,
date DATETIME,
special_handling_note TEXT,
PRIMARY KEY (donut_order_id),
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
);
INSERT INTO salesorders
(donut_order_id,date,special_handling_note)
VALUES( 0000001,"2018-04-22","Please include plates and napkins");
CREATE TABLE salesorderslineitem
(
donut_order_id INT(10) NOT NULL,
donut_id INT(10) NOT NULL,
qty INT(10) NOT NULL,
PRIMARY KEY (donut_order_id, donut_id),
FOREIGN KEY (donut_order_id) REFERENCES salesorders(donut_order_id),
FOREIGN KEY (donut_id) REFERENCES donuts(donut_id)
);
INSERT INTO salesorderslineitem
(qty)
VALUES (10);
CREATE TABLE donuts
(donut_id INT(10) NOT NULL AUTO_INCREMENT,
name VARCHAR(30),
description VARCHAR(50),
unit_price DECIMAL(8,3),
PRIMARY KEY (donut_id)
);
INSERT INTO donuts
(name,description,unit_price)