简体   繁体   中英

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!

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 .

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 .

May

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM