2016-12-27 43 views
3

我在學習Laravel一段時間後,爲自己創建了一些基本項目,但是今天我嘗試使用更多整數遷移表。但它仍然有錯誤。Laravel 5.1遷移錯誤自動增加主要

每個整數都試圖成爲auto_increment和primary,它可能是一個問題,但我不知道如何解決它。

 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

有人可以告訴我,我怎麼能解決這個問題呢?要編輯哪些內容才能正確使用它?

非常感謝,祝你有個愉快的一天!

回答

3

刪除秒參數在所有integer()

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

的一點是integer()方法secont參數爲autoIncrement,並把它視爲布爾值。當你通過與false不同的東西時,Laravel認爲你想要這個整數爲auto_increment

+0

謝謝,它的工作原理!你能告訴我,我怎樣才能添加整數的大小?因爲所有整數現在都設置爲int(11),可以在遷移中添加大小嗎?如果是,如何? 謝謝! – Mario

+0

不幸的是,不可能在遷移過程中做到這一點。請記住,int的大小與最小或最大值沒有任何關係,只有在使用'zerofill'時纔有用。這是一個很好的寫法。 https://blogs.oracle.com/jsmyth/entry/what_does_the_11_mean – user3158900

+0

你不能。你可以做的是使用[這些類型的整數](https://laravel.com/docs/5.3/migrations#creating-columns):'tinyInteger','smallInteger','mediumInteger','integer','' bigInteger' –

1

函數的聲明如下所示:

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

因此離開關整數長度,它會正常工作。如果您想要的長度小於11,可以使用smallIntegermediumInteger,長度描述爲here

0

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