【发布时间】:2020-11-29 22:31:10
【问题描述】:
我正在使用 Laravel 6.6.0 和 Doctrine/Dbal 2.10。
我需要更新迁移,并已按照docs 中的信息进行操作。
我有一个小的无符号非自动递增整数,我需要将其更改为整数。
我实际上希望它是 mediumint,但我从 Laravel 文档中了解到这是不支持的。
只有以下列类型可以“更改”:bigInteger、binary、boolean、date、dateTime、dateTimeTz、decimal、integer、json、longText、mediumText、smallInteger、string、text、time、unsignedBigInteger、unsignedInteger 和 unsignedSmallInteger。 我的初始迁移如下:
...
$table->bigIncrements('id');
$table->smallInteger('membership_code')->unsigned();
$table->char('name')->nullable();
...
在安装了 dbal 包后,我正在尝试以下迁移来更新 membership_code 列:
$table->integer('membership_code', 5)->unsigned()->change();
但是当我运行 migrate 命令时,我得到以下信息:
Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key (SQL: ALTER TABLE member_centres CHANGE membership_code membership_code INT UNSIGNED AUTO_INCREMENT NOT NULL
我不明白为什么要在迁移中添加AUTO_INCREMENT?
我没有 increments 类型,为什么要添加它?
【问题讨论】:
标签: laravel doctrine laravel-migrations doctrine-dbal