如何更新表并添加Laravel新行?

时间:2018-01-24 08:51:42

标签: php laravel-5 database-migration

在数据库表中,如下所示;

 public function up()
    {
        Schema::create('current_adresses', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('current_name',50)->nullable();
            $table->string('current_surname',50)->nullable();
            $table->string('telephone',25)->nullable();
          $table->timestamps();
        });
    }

我想做如下;

public function up()
    {
        Schema::create('current_adresses', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('current_name',50)->nullable();
            $table->string('current_surname',50)->nullable();
            $table->string('gsm',25)->nullable();
            $table->string('telephone',25)->nullable();
          $table->timestamps();
        });
    }

如何在不刷新的情况下更新新列(gsm列)(php artisan migrate:refresh)

1 个答案:

答案 0 :(得分:4)

添加new迁移 -

public function up()
{
    Schema::table('current_adresses', function($table) {
        $table->string('gsm',25)->nullable();
    });
}

public function down()
{
    Schema::table('current_adresses', function($table) {
        $table->dropColumn('gsm');
   });
}

请参阅t his链接以便更好地理解。