php - 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:创建表
bookings
(id
int unsigned not null auto_increment 主键,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 主键,instrument_detail
varchar(255) not null,created_at
timestamp null,updated_at
timestamp null) 默认字符集 utf8mb4 collate utf8mb4_unicode_ci)
下面这个
SQLSTATE[42000]:语法错误或访问冲突:1075 表定义不正确;只能有一个自动列,并且必须将其定义为键
解决方案
$table->unsignedTinyInteger('instrument', true);
第二个参数是 bool 自动递增默认为 false
推荐阅读
- python-3.x - 多线程队列正在混合功能
- python - 如何计算图像中的分割级别
- r - 使用 data.table 更改列的值
- ruby-on-rails - rails cocoon嵌套形式的show.html.erb中的未定义方法
- ruby - 是否可以在 Ruby gem 中需要单个文件而不是主 gem 入口点?
- php - if语句检查字符串是否为问号
- node.js - 我正在尝试使用其他输入字段在我的 nodejs 应用程序中上传文件,但没有这样做
- r - 在 R 中使用 lapply 时自定义函数返回错误
- javascript - 清除以前的 setInterval 并在单击提交按钮 React.js 时开始新的 Interval
- dns - 如何将 ibm 云应用程序配置到 Godaddy 域