Php Laravel迁移将自动递增所有数值列。为什么会这样?
您好,我目前正在尝试在Laravel中设置迁移,并且遇到了一个问题,即我的所有数值列都被设置为自动增量 测试迁移:Php Laravel迁移将自动递增所有数值列。为什么会这样?,php,laravel,migration,Php,Laravel,Migration,您好,我目前正在尝试在Laravel中设置迁移,并且遇到了一个问题,即我的所有数值列都被设置为自动增量 测试迁移: Schema::create('sublobbies', function (Blueprint $table) { $table->increments('id'); $table->tinyInteger('sub', 2)->default(1); $table->tinyInteger('anothertable', 2)-&
Schema::create('sublobbies', function (Blueprint $table) {
$table->increments('id');
$table->tinyInteger('sub', 2)->default(1);
$table->tinyInteger('anothertable', 2)->default(1);
$table->tinyInteger('anothertable2', 2)->default(1);
});
除此之外,我得到了一个无效的默认值
错误(我假设是由于自动递增),我注意到所有设置都设置为自动递增:
Syntax error or access violation: 1067 Invalid default val
ue for 'sub' (SQL: create table `sublobbies` (`id` int unsigned not null au
to_increment primary key, `sub` tinyint not null default '1' auto_increment
primary key, `anothertable` tinyint not null default '1' auto_increment pr
imary key, `anothertable2` tinyint not null default '1' auto_increment prim
ary key) default character set utf8mb4 collate utf8mb4_unicode_ci)
这是迁移的自然行为还是我遗漏了什么?如何关闭自动增量
Schema::create('sublobbies', function (Blueprint $table) {
$table->increments('id');
$table->tinyInteger('sub', 2)->default(1); // remove the , 2
$table->tinyInteger('anothertable', 2)->default(1); // remove the , 2
$table->tinyInteger('anothertable2', 2)->default(1); // remove the , 2
});
tinyInteger()函数中的第二个点是一个布尔值,您要将其设置为true,它应该是
Schema::create('sublobbies', function (Blueprint $table) {
$table->increments('id');
$table->tinyInteger('sub')->default(1);
$table->tinyInteger('anothertable')->default(1);
$table->tinyInteger('anothertable2')->default(1);
});
添加此项以供参考:
tinyInteger(字符串$column,bool$autoIncrement=false,bool$unsigned=false)
tinyInteger()函数中的第二个点是一个布尔值,您要将其设置为true,它应该是
Schema::create('sublobbies', function (Blueprint $table) {
$table->increments('id');
$table->tinyInteger('sub')->default(1);
$table->tinyInteger('anothertable')->default(1);
$table->tinyInteger('anothertable2')->default(1);
});
添加此项以供参考:
tinyInteger(字符串$column,bool$autoIncrement=false,bool$unsigned=false)
Laravel不支持指定整型字段的长度,因为许多数据库不使用整型字段。例如,MySQL只使用整数长度作为读取长度。它将把
100
存储在一个小罐子里(1)。@Devon哦,好的,我明白了!Laravel不支持指定整型字段的长度,因为许多数据库不使用它。例如,MySQL只使用整数长度作为读取长度。它将把100
存储在一个小罐子里(1)。@Devon哦,好的,我明白了!那么,我如何在字符串上指定一个类似的长度呢?你没有那么做,我如何在字符串上指定一个类似的长度呢?你没有