jmc1690
jmc1690

Reputation: 95

Creating a table in Mysql with phpadmin

I keep getting errors when trying to create a products table for a database I'm building.

Here is the code I've tried:

CREATE TABLE Products (
    ProductId int NOT NULL auto_increment primary key,
    Name varchar(255) NOT NULL,
    Price decimal(19, 4),
    on_hand integer, 
    supp_id int,
    FOREIGN KEY (supp_id) REFERENCES Suppliers(supp_id)
);

I am getting this error code:

#1005 - Can't create table 'computer_wholesale.products' (errno: 150

Any help would be greatly appreciated.

Upvotes: 0

Views: 49

Answers (1)

NightOwlPrgmr
NightOwlPrgmr

Reputation: 1374

I believe your Suppliers table is missing an index, which is required to use a FOREIGN KEY with.

Upvotes: 1

Related Questions