Laravel table: there can be only one auto column and it must be defined as a key

Use

$table->bigInteger('uid')->unsigned();

instead of

$table->bigInteger('uid', 20)->unsigned();

Infos:

in /vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint you can see the bigInteger function:

public function bigInteger($column, $autoIncrement = false, $unsigned = false)

So 20 (not being 0) evals to true.

While string method has as second parameter length:

public function string($column, $length = null)

Therefore if you use any integer blueprint (bigInteger, mediumInteger, tinyInteger, smallInteger, etc...) with any second parameter (other than 0) you are telling Laravel to make an integer with an auto_increment property, this will return:

Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key")


Specify the size for bigInteger column by following way

$table->bigInteger('uid')->length(20)->unsigned();

Tags:

Mysql

Php

Laravel