我尝试用2个外键创建一个表,但是当我尝试将其写入mysql时,得到一个错误说“ERROR 1005(HY000):无法创建表(错误号:150)”是否存在有人帮我吗?这是我的表:
create table store (
StoreName varchar(255),
Category varchar(20),
primary key(StoreName,Category));
create table shopps (
StoreName varchar(255),
Category varchar(20),
primary key(StoreName,Category),
foreign key(StoreName) References store);
foreign key(Category) References store);
答案 0 :(得分:0)
由于您的store
表具有复合主键,因此在shopps
表中引用它的外键也必须是复合的:
create table shopps (
StoreName varchar(255),
Category varchar(20),
primary key(StoreName,Category),
foreign key(StoreName,Category) References store (StoreName,Category)
)