我有以下迁移:
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
一切似乎都很好,我有一个主键是自动增量等。
答案 0 :(得分:4)
$table->integer('level',5)->unsigned();
那条线就是问题所在。 integer
的第二个参数不是大小。第二个参数是(bool)自动增量。所以你要告诉这个字段是一个自动增量字段。
Illuminate\Database\Schema\Blueprint@integer
:
public function integer($column, $autoIncrement = false, $unsigned = false)