When migrating my DB, this error appears. Below is my code followed by the error that I am getting when trying to run the migration.
Code
In my case the problem was that one of the referenced tables was InnoDB and the other one was MyISAM.
MyISAM doesn't have support for foreign key relations.
So, now both tables are InnoDB. Problem solved.