Mario
Mario

Reputation: 187

Laravel 5.1 migration error auto increment primary

I was learning Laravel for a some time, I create some basic project for myself, but today I was try to migrate table with more integers. But it still take an error.

Every integer try to be auto_increment and primary, it can be a problem, but I do not know, how to resolve it.

        Schema::create ('users', function (Blueprint $table)
    {
        $table->increments ('id');
        $table->string ('email')->unique();
        $table->string ('pass',250);
        $table->integer ('tickets',4);
        $table->integer ('tokens',4);
        $table->integer ('in_raffle',4);
        $table->text ('profile',500);
        $table->string ('ip',20);
        $table->integer ('ban',1);
        $table->integer ('notice',1);
        $table->timestamp ('last_login');

    });

https://s28.postimg.org/fh3uaqdct/screen2.jpg

Can somebody tell me, how can I resolve this problem? What to edit to work it properly?

Thanks a lot, have a nice day!

Upvotes: 3

Views: 1863

Answers (3)

Illia Yaremchuk
Illia Yaremchuk

Reputation: 2025

May

$table->tinyInteger('tickets');
$table->tinyInteger('tokens');
$table->tinyInteger('in_raffle');
$table->boolean('ban')->default(false);
$table->boolean('notice')->default(false);

Upvotes: 0

aynber
aynber

Reputation: 23011

The declaration of the function looks like this:

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

So leave off the integer length, and it will work fine. If you want a smaller integer than a length of 11, you can use smallInteger or mediumInteger, which have lengths described here.

Upvotes: 1

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

Remove seconds parameter in all integer():

$table->integer('tickets');
$table->integer('tokens');
$table->integer('in_raffle');
$table->integer('ban');
$table->integer('notice');

The thing is secont parameter for integer() method is autoIncrement and it's treated as boolean. When you pass something different from false, Laravel thinks you want this integer to be auto_increment.

Upvotes: 6

Related Questions