首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >表定义不正确;只能有一个auto列,并且必须将其定义为键

表定义不正确;只能有一个auto列,并且必须将其定义为键
EN

Stack Overflow用户
提问于 2015-02-06 06:03:18
回答 3查看 20.4K关注 0票数 4

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

        });

    }
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 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.phptinyInteger()函数。正如您所看到的,它在这里需要一个布尔参数。看起来您正在尝试为大小添加一个参数。您不能在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();

这可以很好地工作。

票数 17
EN

Stack Overflow用户

发布于 2019-08-13 05:10:53

尝尝这个

$table->integer('user_id')->length(10)->unsigned();
票数 3
EN

Stack Overflow用户

发布于 2018-06-01 04:31:59

只是补充一下,$table->integer('user_id', 10)也抛出了这个错误,所以我根据Sturm的回答删除了'size‘参数,并在看了Blueprint类之后,现在migrate可以工作了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28354931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档