Php 生产迁移新鲜
如果我想在生产表中添加一个新列,它是如何工作的?我知道在进行迁移时会丢失所有数据:fresh 1) 是否可以像我对fastnetnr列所做的那样更改迁移并添加新列Php 生产迁移新鲜,php,database-migration,laravel-5.6,Php,Database Migration,Laravel 5.6,如果我想在生产表中添加一个新列,它是如何工作的?我知道在进行迁移时会丢失所有数据:fresh 1) 是否可以像我对fastnetnr列所做的那样更改迁移并添加新列 public function up() { Schema::create('kontaktforms',函数(Blueprint$表){ $table->increments('id'); $table->string('navn'); $table->string('mobilnr'); //新增fastnetnr列 $tabl
public function up()
{
Schema::create('kontaktforms',函数(Blueprint$表){
$table->increments('id');
$table->string('navn');
$table->string('mobilnr');
//新增fastnetnr列
$table->string('fastnetnr')->nullable();
$table->string('mail');
$table->string('emne');
$table->text('beskrivelse');
$table->timestamps();
})
从逻辑上讲,您可以通过以下步骤来完成
php artisan迁移:回滚或php artisan
迁移:回滚--步骤=1
php artisan migrate
php artisan make:migration add_fastnetnr_to_kontaktforms_table --table=kontaktforms
并添加如下新列
public function up()
{
Schema::table('kontaktforms', function (Blueprint $table) {
$table->string('fastnetnr')->nullable();
});
}
public function down()
{
Schema::table('kontaktforms', function (Blueprint $table) {
$table->dropColumn('fastnetnr');
});
}
和迁移
php artisan migrate
如果我不执行migrate:rollback,而只执行migrate:fresh,会不会损坏生产表?migrate:fresh命令将删除所有表并重新运行所有迁移