Laravel 1075 table 定义不正确;只能有一个自动列,并且必须将其定义为键
Laravel 1075 Incorrect table definition; there can be only one auto column and it mus t be defined as a key
当我尝试在 laravel 中迁移此 table 时。
命令输出为:
[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
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->bigInteger('post_author', 20);
$table->text('post_title');
$table->longText('post_content');
$table->string('post_status', 20);
$table->string('comment_status', 20);
$table->string('post_type', 20);
$table->timestamps();
$table->softDeletes();
});
}
不要为 bigInteger 列指定大小
$table->bigInteger('post_author');
通过以下方式指定 bigInteger 列的大小
$table->bigInteger('post_author')->length(20);
当我尝试在 laravel 中迁移此 table 时。
命令输出为:
[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
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->bigInteger('post_author', 20);
$table->text('post_title');
$table->longText('post_content');
$table->string('post_status', 20);
$table->string('comment_status', 20);
$table->string('post_type', 20);
$table->timestamps();
$table->softDeletes();
});
}
不要为 bigInteger 列指定大小
$table->bigInteger('post_author');
通过以下方式指定 bigInteger 列的大小
$table->bigInteger('post_author')->length(20);