Laravel migration: malformed foreign key constraint
I am using migrations to change a field to nullable () using the following code.
$table->integer('recipe_id')->nullable()->change();
But I am getting the following error.
SQLSTATE[HY000]: General error: 1025 Error on rename of './blackfisk/#sql-2
2d_a' to './blackfisk/preparations' (errno: 150 "Foreign key constraint is
incorrectly formed") (SQL: ALTER TABLE preparations CHANGE recipe_id recipe
_id INT DEFAULT NULL)
I tried to set foreign key validation to 0 using
\DB::statement('SET FOREIGN_KEY_CHECKS=0');
But this gives the same error. When I try to run a query in Sequel Pro I also get this error using the following query.
SET FOREIGN_KEY_CHECKS = 0;
ALTER TABLE preparations CHANGE recipe_id recipe_id INT DEFAULT NULL;
SET FOREIGN_KEY_CHECKS = 1;
Any Idea If I'm missing something? Thank!
+3
source to share