我试着在我的SQL数据库中创建这样的:
CREATE TABLE OrderID (
order_id INT AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(255) NOT NULL,
book_title VARCHAR(255) NOT NULL,
delivery_method VARCHAR(255) NOT NULL,
password_confirmation VARCHAR(255) NOT NULL,
FOREIGN KEY (customer_name) REFERENCES customer(customer_name),
FOREIGN KEY (book_title) REFERENCES book(book_title),
FOREIGN KEY (password_confirmation) REFERENCES customer(customer_password)
);
但它总是显示错误:
CREATE TABLE OrderID (
order_id INT AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(255) NOT NULL,
book_title VARCHAR(255) NOT NULL,
delivery_method VARCHAR(255) NOT NULL,
password_confirmation VARCHAR(255) NOT NULL,
FOREIGN KEY (customer_name) REFERENCES customer(customer_name),
FOREIGN KEY (book_title) REFERENCES book(book_title),
FOREIGN KEY (password_confirmation) REFERENCES customer(customer_password)
) ENGINE=InnoDB;
MySQL说:文档
1005 -无法创建表book_store
. orderid
(错误号:150“外键约束格式不正确”)(详细信息...)`
请告诉我正确的语法!
1条答案
按热度按时间nr7wwzry1#
确保在customer和book上创建了
indexes/keys
,以便它们(列)可以作为新表的外键对于您的情况,请执行以下操作(如果尚未执行):
和
完成上述操作后,再次尝试创建OrderID表。