I am trying to add a foreign key to a table that has a composite key. I was able to add the foreign key for the first column but not the second.
I have searched stackoverflow, reading all of the similar questions. I've searched the internet. I have checked the parent tables against the child table and the column definitions appear to be the same. I've checked the spelling of the column names. I have used another alter statement that worked for another foreign key. I'm at a loss.
Table: orderdetails
Columns:
OrderID int(11) PK
ProductID int(11) PK
Table: products
Columns:
productid int(11) AI PK
ALTER TABLE orderdetails
ADD CONSTRAINT fk_od_prodid
FOREIGN KEY (ProductID) REFERENCES products(productid);
I expected to create the foreign key but got error code 1452 instead.