首页 > 解决方案 > SQLSTATE[42000]:语法错误或访问冲突:1075 表定义不正确;

问题描述

迁移文件

$table->increments('id');
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('band_id')->references('id')->on('bands');
$table->foreign('genre_id')->references('id')->on('genres');
$table->foreign('cate_id')->references('id')->on('cates');
$table->foreign('type_id')->references('id')->on('types');
$table->integer('status');
$table->date('date');
$table->time('time');
$table->decimal('price');
$table->tinyIncrements('instrument');
$table->string('instrument_detail',255);
$table->timestamps();

运行 php artisan migrate 后

SQLSTATE[42000]:语法错误或访问冲突:1075 表定义不正确;只能有一个自动列,并且必须将其定义为键(SQL:创建表bookingsidint unsigned not null auto_increment 主键,statusint not null,date date not null,timetime not null,pricedecimal(8, 2) not null, instrumenttinyint unsigned not null auto_increment 主键, instrument_detailvarchar(255) not null,created_attimestamp null,updated_attimestamp null) 默认字符集 utf8mb4 collat​​e utf8mb4_unicode_ci)

下面这个

SQLSTATE[42000]:语法错误或访问冲突:1075 表定义不正确;只能有一个自动列,并且必须将其定义为键

标签: phplaravelartisan-migrate

解决方案


$table->unsignedTinyInteger('instrument', true);

第二个参数是 bool 自动递增默认为 false


推荐阅读