gpt4 book ai didi

mysql - 插入多个MySQL外键时出错

转载 作者:行者123 更新时间:2023-11-29 07:00:22 26 4
gpt4 key购买 nike

当我尝试将当前表插入到我的 SQL 表中时,出现错误(Products 表):

CREATE TABLE parent(

Barcode INT(9),
PRIMARY KEY (Barcode)
) ENGINE=INNODB;

CREATE TABLE SuppliedBy(

Onr CHAR(10),
OrgNR INT(10),
Date DATE NOT NULL,
PRIMARY KEY (Onr),
FOREIGN KEY (OrgNR) REFERENCES Supplier(OrgNR)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=INNODB;

CREATE TABLE Products(

Onr CHAR(10),
Barcode INT(9),
Quantity INT(10) DEFAULT 0
CHECK (Quantity >= 0),
PRIMARY KEY (Onr, Barcode),
FOREIGN KEY (Onr) REFERENCES SuppliedBy(SSN)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (Barcode) REFERENCES parent(Barcode)
ON DELETE CASCADE
ON UPDATE CASCADE
)ENGINE=INNODB;

我收到以下消息:

#1005 - Can't create table '.\db_project\#sql-b58_6d.frm' (errno: 150)

我确定和这个关系中的几个外键有关,我在网上搜索了一圈,但没有找到解决方案。

最佳答案

没有 SuppliedBy.SSN 列。

FOREIGN KEY (Onr) REFERENCES SuppliedBy(SSN)

也许你的意思是

FOREIGN KEY (Onr) REFERENCES SuppliedBy(Onr)
ON DELETE CASCADE
ON UPDATE CASCADE,

关于mysql - 插入多个MySQL外键时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10516307/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com