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类型是无法指定长度的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持华域联盟。

您可能感兴趣的文章:

声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。