我正在使用迁移将一个字段更改为nullable(),使用以下代码。
$table->integer('recipe_id')->nullable()->change(); 但是我得到了下面的错误。
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)我尝试使用以下命令将外键检查设置为0
\DB::statement('SET FOREIGN_KEY_CHECKS=0');但是它给出了同样的错误。当我尝试在Sequel Pro中运行查询时,我也得到了这个错误,使用以下查询。
SET FOREIGN_KEY_CHECKS = 0;
ALTER TABLE preparations CHANGE recipe_id recipe_id INT DEFAULT NULL;
SET FOREIGN_KEY_CHECKS = 1;你知道我是不是漏掉了什么吗?谢谢!
发布于 2017-07-14 17:15:35
您应该创建一个unsignedInteger
$table->UnsignedInteger('recipe_id')->nullable()->change(); 我希望这能帮到你
https://stackoverflow.com/questions/45098578
复制相似问题