1 Replies - 925 Views - Last Post: 22 July 2014 - 10:06 PM

#1 mpatel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 14-July 14

MySQL Error 1005- Cannot Create Table

Posted 22 July 2014 - 07:04 PM

Using this code
CREATE TABLE lineitems(
OrderNum varchar(20) NOT NULL,
SKU int(15) NOT NULL,
OrderItemQty int(10) NOT NULL,
OrderItemPrice decimal(4,2) NOT NULL,
Tax decimal(4,2),
Discount decimal(4,2),
CONSTRAINT lineitem_pk PRIMARY KEY (OrderNum, SKU),
CONSTRAINT SKU_fk FOREIGN KEY (SKU) REFERENCES items(SKU),
CONSTRAINT lineorderNum_fk FOREIGN KEY (OrderNum) REFERENCES Orders(OrderNum)
);


& it is returning it as



Error
SQL query:

-----
CREATE TABLE lineitems(
OrderNum varchar(20) NOT NULL,
SKU int(15) NOT NULL,
OrderItemQty int(10) NOT NULL,
OrderItemPrice decimal(4,2) NOT NULL,
Tax decimal(4,2),
Discount decimal(4,2),
CONSTRAINT lineitem_pk PRIMARY KEY (OrderNum, SKU),
CONSTRAINT SKU_fk FOREIGN KEY (SKU) REFERENCES items(SKU),
CONSTRAINT lineorderNum_fk FOREIGN KEY (OrderNum) REFERENCES Orders(OrderNum)
)
MySQL said: Documentation

#1005 - Can't create table 'nutsrus.lineitems' (errno: 150) (Details…)

-----


Any suggestions?

This post has been edited by macosxnerd101: 22 July 2014 - 10:07 PM
Reason for edit:: Renamed title to be more descriptive


Is This A Good Question/Topic? 0
  • +

Replies To: MySQL Error 1005- Cannot Create Table

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10562
  • View blog
  • Posts: 39,087
  • Joined: 27-December 08

Re: MySQL Error 1005- Cannot Create Table

Posted 22 July 2014 - 10:06 PM

From the MySQL documentation on Foreign Keys:

Quote

If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1