如何在Laravel迁移中删除“变形”列

如何在Laravel迁移中删除“变形”列,laravel,eloquent,laravel-migrations,Laravel,Eloquent,Laravel Migrations,我正在编辑一个表,以便它使用多态关系: public function up() { Schema::table('locations', function (Blueprint $table) { $table->morphs('location'); }); } 但我不知道扭转这种迁移的最佳方式。我是否必须删除它创建的两列和索引本身,或者在Laravel中有没有一种方法可以在一行中实现这一点?谢谢。在Bluepr

我正在编辑一个表,以便它使用多态关系:

public function up()
    {
        Schema::table('locations', function (Blueprint $table) {
            $table->morphs('location');
        });
    }
但我不知道扭转这种迁移的最佳方式。我是否必须删除它创建的两列和索引本身,或者在Laravel中有没有一种方法可以在一行中实现这一点?谢谢。

在Blueprint api中找到:

所以只要$table->dropMorphs'location'

在Blueprint api中找到:


所以只要$table->dropMorphs'location'

如果有人在处理同一问题时遇到这篇文章,只有像我这样的SQLite DB,SQLite不支持一次性删除列和索引。您需要手动执行此操作,并将其拆分为多个修改,如下所示:

public function down(){
    Schema::table('locations', function (Blueprint $table) {
        $table->dropcolumn('location_id');
    });

    Schema::table('locations', function (Blueprint $table) {
        $table->dropcolumn('location_type');
    });
}

如果有人在处理同一问题时遇到这篇文章,只有像我这样的SQLite DB,SQLite不支持一次性删除列和索引。您需要手动执行此操作,并将其拆分为多个修改,如下所示:

public function down(){
    Schema::table('locations', function (Blueprint $table) {
        $table->dropcolumn('location_id');
    });

    Schema::table('locations', function (Blueprint $table) {
        $table->dropcolumn('location_type');
    });
}