Reputation: 1573
When trying to run the following migration:
Schema::create('languages', function(Blueprint $table){
$table->increments('id');
$table->string('lang', 10);
$table->string('name', 50);
$table->integer('active', 2);
$table->timestamps();
});
I get the following error:
there can be only one auto column and it must be defined as a key
But laravel's documentation states: $table->increments('id'); Incrementing ID to the table (primary key)
Any idea how handle this? Thanks in advance!
Upvotes: 1
Views: 721
Reputation: 152880
The problem is $table->integer('active', 2)
Here's the method signature for integer
:
public function integer($column, $autoIncrement = false, $unsigned = false)
The second argument is actually a flag for auto increment. And 2
evaluates to true
.
You can't specify the length of an integer. However you can use a tinyInteger
instead:
$table->tinyInteger('active');
Upvotes: 1
Reputation: 212412
Your problem is
$table->integer('active', 2);
The second argument passed to integer is a Boolean indicating whether the column should be an autoincrement column or not, and a value of 2
will be treated as a Boolean true
EDIT
If you just want a short integer (like for a Boolean value), then use
$table->tinyinteger('active');
or
$table->boolean('active');
Upvotes: 2