[英]Laravel table: there can be only one auto column and it must be defined as a key
[英]Migration issue : Only one auto column and it must be defined as a key
我有以下迁移:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->integer('level',5)->unsigned();
$table->string('username',60);
$table->string('email')->unique();
$table->string('password');
$table->string('country',3);
$table->string('about',150);
$table->integer('balance')->unsigned();
$table->string('photo_url');
$table->string('photo_id',50);
$table->string('search_tag');
$table->tinyInteger('is_bots');
$table->rememberToken();
$table->timestamps();
});
它引发的错误:
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
一切似乎都很好,我有一个主键是自动增量等。
$table->integer('level',5)->unsigned();
那条线是问题。 integer
的第二个参数不是大小。 第二个参数是(布尔)自动增量。 因此,您告诉此字段是一个自动递增字段。
Illuminate\\Database\\Schema\\Blueprint@integer
:
public function integer($column, $autoIncrement = false, $unsigned = false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.