如何用我的外键约束解决问题

时间:2019-04-11 18:56:50

标签: mysql mysql-error-1005

我试图创建一个LaptopInfo表(该表引用了Laptop表的某些属性),但是外键约束的问题阻止了该表的创建。

我尝试创建不具有“更新时级联...”效果的表,确保引用的属性和表的拼写正确,并且语法对我来说正确,但是问题仍然存在。 / p>

create table Laptop(
    SKU int auto_increment not null,
    modelNo varchar(10) not null,
    brand varchar(25) not null,
    OS varchar(25) not null,
    screenSize decimal(2,1) not null,
    processorBrand varchar(255) not null,
    processorSpd decimal(2,1) not null,
    flashMemory int not null,
    HDsize int not null,
    resolution varchar(25) not null,
    colour varchar(25) not null,
    RAM_size int not null,
    primary key(SKU, modelNo, brand)
);


create table LaptopInfo(
    modelNo varchar(10) not null,
    brand varchar(25) not null,
    price decimal(8,2) not null,
    quantity int not null,
    primary key(modelNo,brand),
    foreign key(modelNo) references Laptop(modelNo) on delete cascade on update cascade,
    foreign key(brand) references Laptop(brand) on delete restrict on update restrict
);

0 个答案:

没有答案