2016-04-01 10 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

あなたが見ることができるように、クエリは2つの主キーを作成しようとします: '' id 'は整数ではなく、主キーの自動インクリメントではなく、 "LoginID"整数ではない主キーautoincrement' – Daan

4

問題は、あなたが第二のparamで機能->integer()を使用することであるdocsによると、2番目のパラメータはブール値が自動インクリメントかどうかを設定することを期待: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(); 
    }); 
} 
関連する問題