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
谁能告诉我该更改什么?
答案 0 :(得分:2)
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();
});
答案 1 :(得分:1)
像这样再试一次。
public function up()
{
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();
});
}
有关更多详细信息,请参阅this。