繁体   English   中英

SQLSTATE [42000]:语法错误或访问冲突:1075表定义不正确;

[英]SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition;

迁移文件

$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后迁移

SQLSTATE [42000]:语法错误或访问冲突:1075表定义不正确; 只能有一个自动列,它必须被定义为一个键(SQL:create table bookingsid int unsigned not null auto_increment primary key, status int not null, date date not null, time time not null, price decimal(8) ,2)not null, instrument tinyint unsigned not null auto_increment primary key, instrument_detail varchar(255)not null, created_at timestamp null, updated_at timestamp null)默认字符集utf8mb4 collat​​e utf8mb4_unicode_ci)

以下是这个

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

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

第二个参数是自动增量的bool,默认为false

下一句话:

$table->foreign('user_id')->references('id')->on('users');

只是告诉db在父/外部列之间建立链接,但为了做到这一点,列必须先存在,所以:

$table->unsignedInteger('user_id'); // first this
$table->foreign('user_id')->references('id')->on('users'); // then this

您应该为每个外键执行此操作。

注意:

Laravel不需要你定义这个链接因为它没有使用它,只是为了数据库一致性。

暂无
暂无

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

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