table 定义不正确;只能有一个自动列,并且必须将其定义为键

Incorrect table definition; there can be only one auto column and it must be defined as a key

我在 Laravel

中迁移时不断出错

[PDOException] 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

代码

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();

        });

    }
/**
 * 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();

这很好用。

补充一下,$table->integer('user_id', 10) 也抛出了那个错误,所以我根据 Sturm 的回答删除了 'size' 参数,并在查看了 Blueprint class 现在 migrate 有效。

试试这个

$table->integer('user_id')->length(10)->unsigned();