Guilherme Costa
Guilherme Costa

Reputation: 310

Laravel Migration return Incorrect table definition

Laravel Migration return "Incorrect table definition; there can be only one auto column and it must be defined as a key", why? Link of Code

Upvotes: 0

Views: 138

Answers (3)

Andrei
Andrei

Reputation: 3588

Damn, consider some atomizing.

The second argument for integer values when creating migrations is NOT the length of the field but rather if it should or it should not be autoincrement.

https://github.com/laravel/framework/blob/330d11ba8cd3d6c0a54a1125943526b126147b5f/src/Illuminate/Database/Schema/Blueprint.php#L443

That's where your problem lies.

For example $table->integer('celular',15)->nullable();. Laravel will assume you want that to be autoincrement as well since 15 is a truthy value and since mysql doesn't allow more than one column to be autoincrement you got yourself an error.

Upvotes: 1

rypskar
rypskar

Reputation: 2092

$table->increments('id')->primary() instead of $table->increments('id') should work. As the error message did say you have not defined the column as primary key

Upvotes: 0

Tiberiu Petcu
Tiberiu Petcu

Reputation: 852

check your table structure you most probably want to build a table with two auto increment columns, which is not possible

Upvotes: 0

Related Questions