繁体   English   中英

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

[英]Laravel 5.0, migration: how to make integer not a primary key?

我想迁移包含以下元素的表格。

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();
    });
}

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

[照明\\数据库\\查询异常]
SQLSTATE[HY000]: 一般错误: 1 表 "users" 有多个主键 (SQL: create table "users" ("id" integer not null primary key autoincrement, "LoginID" integer not null primary key autoincrement, "username" " varchar 非空,"email" varchar 非空,"password" varchar 非空,"remember_token" varchar 空,"created_at" 日期时间非空,"updated_at" 日期时间非空))

问题是您将函数->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();
    });
}

试试这个

$table->integer('company_tel')->length(10)->unsigned();

或者这个

$table->integer('company_tel', false, true)->length(10);

查看详情https://laracasts.com/discuss/channels/general-discussion/why-am-i-getting-a-database-error-on-migration

试试这个

$table->increments('id', true);

这将自动增加 id 而不创建其主键。

你不应该打电话吗

$table->primary('id');

将 id 列标记为主键?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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