laravel - Laravel 数据库迁移 表定义不正确
问题描述
public function up()
{
Schema::create('materials', function (Blueprint $table) {
$table->increments('id');
$table->string('name',60);
$table->integer('category_id',10);
$table->integer('low_bulk',10);
$table->integer('high_bulk',10);
$table->integer('order_level',10);
$table->decimal('unit_price',10,2);
$table->string('description');
$table->timestamps();
});
}
此架构给了我以下错误
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
谁能告诉我应该改变什么?
解决方案
的第二个参数integer()
不是长度,而是列是否应该自动递增。PHP 转换10
为true
并尝试使所有这些列自动递增。
去掉它,长度对 MySQL 没有任何影响:
Schema::create('materials', function (Blueprint $table) {
$table->increments('id');
$table->string('name',60);
$table->integer('category_id');
$table->integer('low_bulk');
$table->integer('high_bulk');
$table->integer('order_level');
$table->decimal('unit_price',10,2);
$table->string('description');
$table->timestamps();
});
推荐阅读
- sql - SQL 将行从一个表分配到另一个表
- ansible - 如何使用 ansible 清除不在列表中的任何 ufw 条目
- qt - Qt QML 有 TabButton 获取自己的索引
- linux - OpenCV:如何获取可用编解码器的列表?
- javascript - 尝试制作立方码计算器但公式不一致
- safari - Safari:重新加载后“由于访问控制检查而无法加载 Fetch API”
- angular - ControlValueAccessor 无法清除输入值
- kubernetes - CoreDNS 将所有 DNS 查询转发到本地路由器,包括集群内服务名称的查询
- javascript - Swiper.js 分页自定义项目符号不会点击移动到下一张幻灯片
- linux - 使用 signal_pending_state 函数将任务状态更改为 TASK_RUNNING