您好我正在尝试在Laravel中设置迁移,并且我遇到的问题是我的所有数字列都设置为自动增量。
测试迁移:
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);
});
除了事实,我收到Invalid default value
错误(我假设由于自动增量),我注意到所有内容都设置为自动增量:
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)
这是迁移的自然行为还是我错过了什么?如何关闭auto_increment?
答案 0 :(得分:3)
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(string $ column,bool $ autoIncrement = false,bool $ unsigned = false)
https://laravel.com/api/4.2/Illuminate/Database/Schema/Blueprint.html#method_tinyInteger