我建了一个user表,但是运行artisan migrate保存

就是这个表,运行命令后保存,我把sql语句复制出来,发现tinyInteger字段,默认被设置为主键,所以报错,求解


Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('username')->unique();
            $table->string('email')->unique();
            $table->string('telephone')->unique();
            $table->string('qq')->unique();
            $table->string('weixin')->unique();
            $table->string('sina')->unique();
            $table->string('password', 60);
            $table->string('name',50);
            $table->string('face');
            $table->tinyInteger('sex',1);
            $table->integer('age',3);
            $table->string('intro');
            $table->string('idcard');
            $table->string('bcard');
            $table->string('acard');
            $table->string('provincecode');
            $table->string('citycode');
            $table->string('areacode');
            $table->string('district _id');
            $table->string('address');
            $table->tinyInteger('is_check',1);
            $table->tinyInteger('is_look',1);
            $table->tinyInteger('status',1);
            $table->tinyInteger('type',1);
            $table->integer('login_counts',11);
            $table->timestamp('login_time');
            $table->string('login_ip');
            $table->timestamp('last_time');
            $table->string('last_ip');
            $table->decimal('total_money',11,2);
            $table->decimal('get_money',11,2);
            $table->decimal('could_money',11,2);
            $table->rememberToken();
            $table->timestamps();
        });
JellyBool

不明白问题是什么意思?

a416237796

@JellyBool 就是我在user表的生成器里加了这么多字段,运行创建数据表的命令的时候报错,然后错误信息里面显示的sql语句中tinity类型的字段全部被加上了主键的设置,导致数据表创建失败

a416237796

@我想请问下是不是我字段设置哪里写错了

JellyBool

嗯,大概是这里写错了:

 $table->tinyInteger('is_check',1)

第二参数是是否设为主键,你都设置为1,也就看成了true,所以。。。

如果你想设置默认值的话,使用

 $table->tinyInteger('is_check')->default(1);
a416237796

@JellyBool 原来如此,那则么设置这个字段的字数呢

sj1370201

@JellyBool 长度我也想知道啊~