laravel中migrate运行迁移文件给数据库表新增字段

在laravel中表创建成功后

如何在表中新增字段

运行命令

`$ php artisan make:migration add_field_into_testtable`

然后打开文件`database/migrations/2022_09_02_1238_add_field_into_testtable.php`

内容如下

```

string('field')->after('name')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('table_testtable', function (Blueprint $table) {
$table->dropColumn('field');
});
}
}

执行命令

$ php artisan migrate
Migrating: 2022_09_02_1238_add_field_into_testtable
Migrated: 2022_09_02_1238_add_field_into_testtable (0.06 seconds)

Administrator@DESKTOP-64TSROO MINGW64 /d/phpstudy_pro/WWW (feature-yansiyu)

回滚操作

$ php artisan migrate:rollback
Rolling back: 2022_09_02_1238_add_field_into_testtable
Rolled back: 2022_09_02_1238_add_field_into_testtable (0.06 seconds)

```

    A+
发布日期:2022年09月02日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: