这是我的代码:
public function up()
{
Schema::create('sysmods', function (Blueprint $table) {
$table->increments('mod_id');
$table->string('mod_name','60');
$table->string('mod_alias_name','60');
$table->integer('mod_tb_id','6');// this will become auto increment?
$table->timestamps();
});
}
当我运行migrate命令时,它说:“[PDOException] SQLSTATE [42000]:语法错误或访问冲突:1075表定义不正确;只能有一个自动列,必须将其定义为键”
然后当我检查sql时,我发现了这个:(SQL:create table la_sysmods
( mod_id
int unsigned not null auto_increm ent primary key, mod_name
varchar(60)not null, mod_alias_name
varchar(60)not null, mod_tb_id int not null auto_increment primary key , created _at
timestamp null, updated_at
timestamp null)默认字符集utf 8 collate utf8_unicode_ci)
标记为整数的字段“mod_tb_id”已成为增量 . 有什么问题?谢谢!
2 回答
integer方法的第二个参数是autoIncrement变量 . 你需要删除它 .
The Laravel method
改变这个:
对此:
你需要更换你的
同
要么
integer()方法的第二个参数是
autoincrement
的标志,第三个参数是unsigned
.希望能帮助到你