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
For me, the 1215 error occurred when I was importing a dumpfile created by mysqldump
, which creates the tables alphabetically, which in my case, caused foreign keys to reference tables created later in the file. (Props to this page for pointing it out: https://www.percona.com/blog/2017/04/06/dealing-mysql-error-code-1215-cannot-add-foreign-key-constraint/)
Since mysqldump orders tables alphabetically and I did not want to change the names of tables, I followed the instructions in the answer by JeremyWeir on this page, which states to put set FOREIGN_KEY_CHECKS = 0;
at the top of the dump file and put SET FOREIGN_KEY_CHECKS = 1;
at the bottom of the dump file.
That solution worked for me.