Laravel 5.0,迁移:如何使整数不是主键?

ILo*_*max 7 php database-migration laravel-5

我想用下面的元素迁移一个表.

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();
    });
}
Run Code Online (Sandbox Code Playgroud)

但是,我一直在处理下面的错误.有谁知道如何使整数"LoginID不是主键,以便我可以迁移下面的表?任何建议赞赏.提前谢谢.

[Illuminate\Database\QueryException]
SQLSTATE [HY000]:一般错误:1表"users"有多个主键(SQL:create table"users"("id"整数not null主键自动增量,"LoginID"整数不是null主键autoincrement,"username"varchar not null,"email"varchar not null,"password"varchar not null,"remember_token"varchar null,"created_at"日期时间不为空,"updated_at"datetime not null))

Daa*_*aan 5

问题是您将函数->integer()与第二个参数一起使用。根据文档,第二个参数需要一个布尔值来设置是否自动递增:)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();
    });
}
Run Code Online (Sandbox Code Playgroud)


小智 -1

你不应该打电话吗

$table->primary('id');
Run Code Online (Sandbox Code Playgroud)

将 id 列标记为主键?