create table orderdetail
(
id int UNSIGNED AUTO_INCREMENT PRIMARY KEY,
oid varchar(20) ,
fname varchar(20) ,
fprice decimal(5,2),
num SMALLINT UNSIGNED not null,
subtotals decimal(5,2) not null,
CONSTRAINT fk_orderdetail_oid
FOREIGN KEY (oid
) REFERENCES orders
(oid
),
CONSTRAINT fk_orderdetail_fname
FOREIGN KEY (fname
) REFERENCES fruit
(fname
),
CONSTRAINT fk_orderdetail_fprice
FOREIGN KEY (fprice
) REFERENCES fruit
(fprice
)
);
顯示錯誤信息是
[Err] 1215 - Cannot add foreign key constraint
求問大神出錯了在哪呢這語法!!在線等!!
(1)外鍵對應的字段數據類型不一致
(2)兩張表的存儲引擎不一致
(3)設置外鍵時“刪除時”設置為“SET NULL”