I am trying to forward engineer my new schema onto my db server, but I can\'t figure out why I am getting this error. I\'ve tried to search for the answer here, but everyth
This also happens when the type of the columns is not the same.
e.g. if the column you are referring to is UNSIGNED INT and the column being referred is INT then you get this error.
For me it was the column types. BigINT != INT.
But then it still didn't work.
So I checked the engines. Make sure Table1 = InnoDB and Table = InnoDB
In my case I had to disable FOREIGN KEY
checks as the source tables did not exist.
SET FOREIGN_KEY_CHECKS=0;
I had the same error once. I just simply restarted the MySQL server and fixed the problem.
Reasons you may get a foreign key constraint error:
key
)Update:
ON DELETE SET NULL
is not defined to be null. So make sure that the column is set default null.Check these.
In my case, I had deleted a table using SET FOREIGN_KEY_CHECKS=0
, then SET FOREIGN_KEY_CHECKS=1
after. When I went to reload the table, I got error 1215
. The problem was there was another table in the database that had a foreign key to the table I had deleted and was reloading. Part of the reloading process involved changing a data type for one of the fields, which made the foreign key from the other table invalid, thus triggering error 1215
. I resolved the problem by dropping and then reloading the other table with the new data type for the involved field.