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
有人能告诉我我应该改变什么吗?
发布于 2018-10-22 01:43:11
像这样再试一次。
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。
发布于 2018-10-22 01:43:02
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();
});
https://stackoverflow.com/questions/52918013
复制相似问题