LuluLala
LuluLala

Reputation: 25

Creating table 'ShoppingCart' in MySQL - error 1005

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.

Upvotes: 1

Views: 94

Answers (1)

willy
willy

Reputation: 1490

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.

Upvotes: 1

Related Questions