如何在迁移中改变领域类型?

时间:2020-08-10 11:09:16

标签: laravel

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

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

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

2 个答案:

答案 0 :(得分:1)

通过以下方式进行新迁移:

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

答案 1 :(得分:1)

如果您像我之前用5.7&5.8和MySql 8遇到了一些mysql问题,则可以在迁移中进行RAW查询

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

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

}