1

I've created a table in MySQL named 'ShoppingCart', but it shows error 1005. What's the mistake here?

 mysql> create table ShoppingCart(
    -> Current_Purchases varchar(100),
    -> Previous_Purchases varchar(100),
    -> Phone_No int(20),
    -> constraint fk_shop foreign key (Phone_No) references Registration(Phone_No));
ERROR 1005 (HY000): Can't create table 'infoproject.shoppingcart' (errno: 150)

The other table 'Registration' is already created and the same column is present with the same datatype.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
LuluLala
  • 25
  • 2
  • 9

1 Answers1

1

The column referenced by a foreign key has to be unique. In your case, it seems like the error is due to a non-unique Phone_No in Registration. Alter the Registration table to add a unique index on Phone_No.

willy
  • 1,462
  • 11
  • 12