2016-04-01 38 views
5

我想用下面的元素移植一張表格。Laravel 5.0,遷移:如何使整數不是主鍵?

public function up() { 
    Schema::create('users', function(Blueprint $table) { 
     $table->increments('id'); 
     $table->integer('LoginID', 9)->unsigned(); 
     $table->string('username'); 
     $table->string('email')->unique(); 
     $table->string('password', 60)->unique(); 
     $table->rememberToken(); 
     $table->timestamps(); 
    }); 
} 

但是,我一直在處理下面的錯誤。 有誰知道如何使整「登錄ID不是主鍵,這樣我可以遷移見下表?任何意見讚賞。在此先感謝。

[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1 table "users" has more than one primary key (SQL: create table "users" ("id" integer not null primary key autoincrement, "LoginID" integer not null primary key autoincrement, "username" varchar not null, "email" varchar not null, "password" varchar not null, "remember_token" varchar null, "created_at" date time not null, "updated_at" datetime not null))

+0

有東西掉。您所做的遷移中沒有任何內容會導致LoginID成爲自動遞增主鍵。 – patricus

+0

我不知道原因,但幾個小時後才奏效。 – ILoveBaymax

回答

0

你不應該叫

$table->primary('id'); 

要將id列標記爲主鍵?

+0

正如你所看到的,查詢試圖創建兩個主鍵:''id「整數不爲null主鍵自動增量,」LoginID「整數不爲null主鍵自動增量' – Daan

4

問題是,您使用函數->integer()與第二個參數。根據docs第二個參數需要一個布爾值來設置自動增量或不:bool $autoIncrement = false)。

試試這個:

public function up() { 
    Schema::create('users', function(Blueprint $table) { 
     $table->increments('id'); 
     $table->integer('LoginID')->unsigned(); 
     $table->string('username'); 
     $table->string('email')->unique(); 
     $table->string('password', 60)->unique(); 
     $table->rememberToken(); 
     $table->timestamps(); 
    }); 
}