I want to create 2 tables in MySQL where the second table has a foreign key from my base table.
The problem is when I try to create the second table I get errno:150. Which fails because the foreign keys are null.
How can I create the second table properly?
More details
My first table has 5 attributes and the first attribute is the Primary key.
My second table has 3 attributes. The 1st and 2nd attribute of this table reference the first 2 attributes from the first table.
All the variables are varchar and all are same length. Any suggestions?
I think the proper way to fix this, given that we can’t see your code, would be on MySQL – Foreign Key documentation page.
See their example below:
This line is precisely what you need to do :
FOREIGN KEY (parent_id) REFERENCES parent(id).