繁体   English   中英

表定义不正确; 只能有一个自动列

[英]Incorrect table definition; there can be only one auto column

迁移文件

public function up()
{
    Schema::create('progress', function (Blueprint $table) {
        $table->id();
        $table->foreignId('state_id')->constrained()->cascadeOnDelete();
        $table->foreignId('city_id')->constrained()->cascadeOnDelete();
        $table->text('address');
        $table->string('project_name');
        $table->tinyInteger('status', 2);
        $table->timestamps();
    });
}

运行 php artisan migrate 后

SQLSTATE[42000]:语法错误或访问冲突:1075 表定义不正确; 只能有一个自动列,并且必须将其定义为键(SQL:创建表progressid bigint unsigned not null auto_increment 主键, state_id bigint unsigned not null, city_id bigint unsigned not null, address文本不 null, project_name varchar (255) 不为空, status tinyint 不为空 auto_increment 主键, created_a t时间戳为空, updated_at时间戳为空)默认字符集 utf8mb4 collat​​e 'utf8mb4_unicode_ci')

您的迁移已将微小整数列定义为自动增量列。 查看 Laravel tinyInterger文档,您会看到第二个参数是一个布尔值,用于将列定义为自动增量。

因此,要删除此错误,您需要从列定义中删除 2。

暂无
暂无

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

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