尝试在表供应商上为供应商 ID 引用表付款创建外键。
CREATE TABLE Payment (
Supplier_ID INT (4) NOT NULL,
Date DATE NOT NULL,
Amount INT (4),
Payment_ID INT (4) NOT NULL,
PRIMARY KEY (Payment_ID, Supplier_ID)
);
Query OK, 0 rows affected (0.10 sec)
CREATE TABLE Supplier (
Supplier_ID INT(4) NOT NULL,
Name VARCHAR(4) NOT NULL,
Country VARCHAR(4) NOT NULL,
Reliability_Score INT(4),
Contact_Info VARCHAR(4),
PRIMARY KEY (Supplier_ID)
FOREIGN KEY (Supplier_ID) REFERENCES Payment(Supplier_ID)
);
ERROR 1215 (HY000): Cannot add foreign key constraint
如果我能提供更多信息,请告诉我,谢谢。