我们最近进行了服务提供商的转换,以便需要重命名此项目的数据库表中的多个列。
我知道this帖子,其中显示了如何从1个表中重命名1列:
php artisan migrate:make rename_stk_column --table="YOUR TABLE" --create
有没有办法用多列执行同样的迁移? (1次迁移,不超过1次......尝试最小化创建的迁移文件数量)
答案 0 :(得分:2)
你可以添加多个renameColumn();需要在给定表中更新的每列的语句。只需要提出你们/ gals用于迁移文件的名称。
只是我跑的样本
class MultipleColumnUpdate extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function ($table) {
$table->renameColumn('name', 'user_name');
$table->renameColumn('email', 'work_email');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function ($table) {
$table->renameColumn('user_name', 'name');
$table->renameColumn('work_email', 'email');
});
}
}