在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)
```