在Laravel中迁移时,我不断收到错误
PDOException SQLSTATE42000:语法错误或访问冲突: 1075表定义不正确;只能有一个auto列,并且必须将其定义为键
代码
public function up()
{
Schema::create('inventories', function($table){
$table->engine = 'InnoDB';
$table->increments('id')->unsigned();
$table->string('sku',255);
$table->string('description', 255 )->nullable;
$table->tinyInteger('stock',5)->nullable()->unsigned();
$table->tinyInteger('day_of_week',1)->unsigned();
$table->text('note')->nullable();
$table->timestamps();
});
}
发布于 2015-02-06 06:40:11
/**
* Create a new tiny integer column on the table.
*
* @param string $column
* @param bool $autoIncrement
* @param bool $unsigned
* @return \Illuminate\Support\Fluent
*/
public function tinyInteger($column, $autoIncrement = false, $unsigned = false)
{
return $this->addColumn('tinyInteger', $column, compact('autoIncrement', 'unsigned'));
}
这是来自Blueprint.php
的tinyInteger()
函数。正如您所看到的,它在这里需要一个布尔参数。看起来您正在尝试为大小添加一个参数。您不能在Laravel中指定tinyint的大小。
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('sku',255);
$table->string('description', 255 )->nullable();
$table->tinyInteger('stock')->nullable()->unsigned();
$table->tinyInteger('day_of_week')->unsigned();
$table->text('note')->nullable();
这可以很好地工作。
发布于 2019-08-13 05:10:53
尝尝这个
$table->integer('user_id')->length(10)->unsigned();
发布于 2018-06-01 04:31:59
只是补充一下,$table->integer('user_id', 10)
也抛出了这个错误,所以我根据Sturm的回答删除了'size‘参数,并在看了Blueprint
类之后,现在migrate
可以工作了。
https://stackoverflow.com/questions/28354931
复制相似问题