我有一个叫做locations
的数据库表,需要添加一个新的status
列。我设置了以下迁移文件,当我运行php artisan migrate
时,可以成功添加字段,但是如何为表中的每一行插入值Active
呢?
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddStatusToLocationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('locations', function(Blueprint $table)
{
$table->string('status')->after('email');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('locations', function(Blueprint $table)
{
$table->dropColumn('status');
});
}
}
DB::table('your-table')->update([...])
没有where
条件,意味着它将更新所有记录。您需要循环遍历所有行并逐个更新UUID。 - Iamzozo