Guilherme Costa Guilherme Costa - 1 year ago 143
PHP Question

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

Answer Source

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.

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download