0

I've tried to create a table,with 2 foreign key but when I tried to write it into mysql, get an error says "ERROR 1005 (HY000): Can't create table (errno: 150)" Is there anyone to help me ? Here is my tables:

  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);
4

1 回答 1

0

由于您的store表具有复合主键,因此在shopps表中引用它的外键也必须是复合的:

create table shopps (
    StoreName varchar(255),
    Category varchar(20),
    primary key(StoreName,Category),
    foreign key(StoreName,Category) References store (StoreName,Category)
)

sqlfiddle 上的演示。

于 2013-11-09T09:07:35.737 回答