我已经使用迁移创建了一个表,如下所示:
public function up()
{
Schema::create('despatch_discrepancies', function($table) {
$table->increments('id')->unsigned();
$table->integer('pick_id')->unsigned();
$table->foreign('pick_id')->references('id')->on('picks');
$table->integer('pick_detail_id')->unsigned();
$table->foreign('pick_detail_id')->references('id')->on('pick_details');
$table->integer('original_qty')->unsigned();
$table->integer('shipped_qty')->unsigned();
});
}
public function down()
{
Schema::drop('despatch_discrepancies');
}
我需要更改此表并删除外键引用和列,pick_detail_id
并添加一个新的varchar列,此列称为sku
after pick_id
column。
因此,我创建了另一个迁移,如下所示:
public function up()
{
Schema::table('despatch_discrepancies', function($table)
{
$table->dropForeign('pick_detail_id');
$table->dropColumn('pick_detail_id');
$table->string('sku', 20)->after('pick_id');
});
}
public function down()
{
Schema::table('despatch_discrepancies', function($table)
{
$table->integer('pick_detail_id')->unsigned();
$table->foreign('pick_detail_id')->references('id')->on('pick_details');
$table->dropColumn('sku');
});
}
运行此迁移时,出现以下错误:
[Illuminate \ Database \ QueryException]
SQLSTATE [HY000]:常规错误:1025将“ ./dev_iwms_reboot/despatch_discrepancies”重命名为“ ./dev_iwms_reboot/#sql2-67c-17c464”(错误:152)(SQL:更改表)时出错despatch_discrepancies
删除外键pick_detail_id)[PDOException]
SQLSTATE [HY000]:常规错误:1025将“ ./dev_iwms_reboot/despatch_discrepancies”重命名为“ ./dev_iwms_reboot/#sql2-67c-17c464”时出错(错误:152)
当我尝试通过运行php artisan migrate:rollback
命令来逆转这种迁移时,我收到一条Rolled back
消息,但实际上并没有在数据库中做任何事情。
知道有什么问题吗?如何删除具有外键引用的列?