如何解决laravel数据库迁移中integer类型是无法指定长度的问题

这篇文章主要为大家展示了“如何解决laravel数据库迁移中integer类型是无法指定长度的问题”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“如何解决laravel数据库迁移中integer类型是无法指定长度的问题”这篇文章吧。

laravel数据库迁移中integer类型是无法指定长度的,很多小伙伴对integer类型传递第二个参数后会发现迁移报以下错误

Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key

查看了sql代码后发现通过integer指定长度创建的子段自动添加了auto increament 以及 primary key 属性

int not null auto_increment primary key

查看源代码后发现integer方法的第二个参数并不是指定长度,而是是否设置auto increment,所以integer方法无法指定子段长度,默认为11。

 public function integer($column, $autoIncrement = false, $unsigned = false)
  {
  return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned'));
 }

以上是“如何解决laravel数据库迁移中integer类型是无法指定长度的问题”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!