Home > Archive > PHP SQL > June 2006 > Foreign key error
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| jason.m.ho@gmail.com 2006-06-24, 8:06 am |
| Why does creating the following table give me the error: ERROR 1005
(HY000): Can't create table (errno: 150)
CREATE TABLE orderProducts (
orderID integer(10),
productID integer(10),
quantity integer(10),
PRIMARY KEY (orderID, productID),
FOREIGN KEY (orderID) REFERENCES orders (orderID),
FOREIGN KEY (productID) REFERENCES products (productID)
);
Can i not say that attributes that are part of the primary key are also
foreign keys?
- Jason
| |
| Andy Hassall 2006-06-24, 8:06 am |
| On 23 Jun 2006 00:58:49 -0700, jason.m.ho@gmail.com wrote:
>Why does creating the following table give me the error: ERROR 1005
>(HY000): Can't create table (errno: 150)
>
>CREATE TABLE orderProducts (
>orderID integer(10),
>productID integer(10),
>quantity integer(10),
>PRIMARY KEY (orderID, productID),
>FOREIGN KEY (orderID) REFERENCES orders (orderID),
>FOREIGN KEY (productID) REFERENCES products (productID)
> );
>
>Can i not say that attributes that are part of the primary key are also
>foreign keys?
http://dev.mysql.com/doc/refman/5.0...onstraints.html
You'll need an index on productID.
It ought to be able to use the primary key index for orderID, though.
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
|
|
|
|
|