[英]Laravel 5.0, migration: how to make integer not a primary key?
I would like to migrate a table with the elements below.我想迁移包含以下元素的表格。
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();
});
}
However, I have kept dealing with the error below.但是,我一直在处理下面的错误。 Does anyone know how to make integer "LoginID not a primary key so that I can migrate the table below? Any advice appreciated. Thanks in advance.
有谁知道如何使整数“LoginID 不是主键,以便我可以迁移下表?感谢任何建议。提前致谢。
[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))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" 日期时间非空))
The problem is that you use the function ->integer()
with a second param.问题是您将函数
->integer()
与第二个参数一起使用。 According to the docs the second parameter expects a boolean to set autoincrement or not: bool $autoIncrement = false
).根据文档,第二个参数需要一个布尔值来设置自动增量与否:
bool $autoIncrement = false
)。
Try this:试试这个:
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();
});
}
try this试试这个
$table->integer('company_tel')->length(10)->unsigned();
or this或者这个
$table->integer('company_tel', false, true)->length(10);
see details https://laracasts.com/discuss/channels/general-discussion/why-am-i-getting-a-database-error-on-migration查看详情https://laracasts.com/discuss/channels/general-discussion/why-am-i-getting-a-database-error-on-migration
Try this试试这个
$table->increments('id', true);
This will auto increments the id without creating its primary key.这将自动增加 id 而不创建其主键。
Shouldn't you call你不应该打电话吗
$table->primary('id');
to mark id column as a primary key?将 id 列标记为主键?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.