生成迁移
php artisan make:migration upgrade_to_v15
class UpgradeToV15 extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//调用artisan
\Illuminate\Support\Facades\Artisan::call('test:xxxx');
//使用SQL更新数据
$sql = "UPDATE `users` SET `name` = 'root' WHERE (`id` = 1)";
DB::statement($sql);
//调用函数
$this->addSth();
//更改字段
if (!Schema::hasColumn('users', 'phone')) {
Schema::table('users', function (Blueprint $table) {
$table->string('phone')->default(null)->comment('电话');
});
}
//新增表
Schema::create('asset_websites_extra', function (Blueprint $table) {
$table->collation = 'utf8mb4_general_ci';
$table->bigIncrements('id');
$table->integer('website_id');
$table->timestamps();
$table->index('website_id', 'website_id');
});
}
public function addSth() {
//todo sth.
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//此处操作危险,最好不要进行什么删表等危险操作, 但可以删除一些缓存
}
}
运行迁移
php artisan migrate