dongying9756 2018-12-04 10:20
浏览 46
已采纳

生产迁移新鲜

How does it work if I want to add a new column in my production table? I know that I will loose all the data when I make a migration:fresh.

1) is it possible to change the migration and add a new column as I did with the fastnetnr column?

 public function up()
    {
        Schema::create('kontaktforms', function (Blueprint $table) {
            $table->increments('id');
            $table->string('navn');
            $table->string('mobilnr');
            //new fastnetnr column added
            $table->string('fastnetnr')->nullable();
            $table->string('mail');
            $table->string('emne');
            $table->text('beskrivelse');
            $table->timestamps();
        });

2) Or do I have to add a new column with php artisan so the output is like this?

public function up()
{
    Schema::table('kontaktforms', function($table) {
        $table->string('fastnetnr')->nullable();
    });
}

</div>
  • 写回答

1条回答 默认 最新

  • donglu4159 2018-12-04 11:14
    关注

    Logically you can do it by following steps;

    1. rollback your table php artisan migrate:rollback or php artisan migrate:rollback --step=1
    2. edit your migration file
    3. migration back php artisan migrate

    but it's not a best practice, especially in production. so you have to create new migration file for modify table and migrate it.

    create new migration file

    php artisan make:migration add_fastnetnr_to_kontaktforms_table --table=kontaktforms
    

    and add new column like this

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

    and migrate

    php artisan migrate
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?