I'm using Laravel 6.6.0 and Doctrine/Dbal 2.10.
I need to update a migration, and have followed the info in the docs.
I have a small unsigned non-auto-incrementing integer which I need to change to an integer.
I actually want it to be mediumint
, but I understand from the Laravel docs that this isn't supported.
Only the following column types can be "changed": bigInteger, binary, boolean, date, dateTime, dateTimeTz, decimal, integer, json, longText, mediumText, smallInteger, string, text, time, unsignedBigInteger, unsignedInteger and unsignedSmallInteger. My initial migration is the following:
...
$table->bigIncrements('id');
$table->smallInteger('membership_code')->unsigned();
$table->char('name')->nullable();
...
And having installed the dbal package, I am trying the following migration to update the membership_code
column:
$table->integer('membership_code', 5)->unsigned()->change();
But when I run the migrate command, I get the following:
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
I don't understand why it's adding AUTO_INCREMENT
to the migration?
I don't have it as an increments
type, so why is it adding it?
The second argument to integer
isn't a size, it is a boolean for whether it should be an autoincrement field or not.
public function integer($column, $autoIncrement = false, $unsigned = false)