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
草莓你们伙计,我认为这个例子有点破了不是吗? –