use one_to_many;
create table models(
model_id int primary key auto_increment unique,
name varchar(50),
manufacturer_id int
);
create table manufacturers(
manufacturer_id int primary key,
name varchar(50),
established_on timestamp,
constraint fk_manufacturers_models foreign key(manufacturer_id)
references models(manufacturer_id)
);
當我嘗試創建一個像這個示例https://ibb.co/bPRGQ5一樣多的模型時,它會拋出錯誤1215 cannot add foreign key constraint
。我究竟做錯了什麼?mysql一對多關係
順便說一句,的PK始終是唯一的 – Strawberry
是不是在錯誤的表上的約束? – Strawberry
草莓你們夥計,我認爲這個例子有點破了不是嗎? –