0

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
jmc1690
  • 75
  • 2
  • 2
  • 8

1 Answers1

1

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

NightOwlPrgmr
  • 1,322
  • 3
  • 21
  • 31