【问题标题】:How in migration to change type of field?如何在迁移中更改字段类型?
【发布时间】:2020-09-03 09:08:33
【问题描述】:

在 Laravel 5.7 中,我使用规则创建了小字段

$table->tinyInteger('renewal_raise_invoice_before')->unsigned()->nullable()->after('renewal_raise_invoice_pre_pay');

但看来我需要更大的范围。 将其类型更改为 smallInteger 的正确方法是什么?

【问题讨论】:

标签: laravel


【解决方案1】:

如果您遇到了一些 mysql 问题,就像我之前在 5.7 & 5.8 和 MySql 8 中运行的那样,您可以在迁移中执行 RAW 查询

Schema::table('table_name',function (Blueprint $table){

  DB::statement('ALTER TABLE table_name MODIFY COLUMN renewal_raise_invoice_before smallint UNSIGNED NULL');

}

【讨论】:

    【解决方案2】:

    使用以下方法进行新迁移:

    Schema::table('sometable',function (Blueprint $table){
            $table->smallInteger('renewal_raise_invoice_before')->unsigned()->nullable()->change();
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-01
      • 2014-05-01
      • 2017-07-28
      • 2013-11-19
      • 2019-02-03
      • 1970-01-01
      • 2020-10-21
      相关资源
      最近更新 更多