阅读(1715) (0)

Laravel 8 删除字段

2021-07-07 09:14:39 更新

可以使用结构生成器上的 dropColumn 方法来删除字段。在从 SQLite 数据库删除字段前,你需要在 composer.json 文件中加入 doctrine/dbal 依赖并在终端执行 composer update 来安装该依赖:

Schema::table('users', function (Blueprint $table) {
    $table->dropColumn('votes');
}); 

你可以传递一个字段数组给 dropColumn 方法来删除多个字段:

Schema::table('users', function (Blueprint $table) {
    $table->dropColumn(['votes', 'avatar', 'location']);
}); 

注意:使用 SQLite 数据库时不支持在单个迁移中 删除修改 多个字段。