【问题标题】:How to just update a table and add new line with Laravel?如何使用 Laravel 更新表格并添加新行?
【发布时间】:2018-07-03 06:01:27
【问题描述】:

在如下数据库表中;

 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)

【问题讨论】:

  • 在控制器中使用模型
  • 我不明白 :(
  • 换行还是换列?

标签: php laravel-5 database-migration


【解决方案1】:

添加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');
   });
}

请参阅 this 链接以获得更好的理解。

【讨论】:

  • 谢谢兄弟。正是我想要的:)
  • @ufuk 接受这个答案,这样做也可以帮助其他人
猜你喜欢
  • 2018-05-30
  • 1970-01-01
  • 2021-04-05
  • 2020-03-03
  • 1970-01-01
  • 1970-01-01
  • 2015-03-23
  • 2011-12-20
  • 2015-09-22
相关资源
最近更新 更多