Laravel数据库迁移中如何设置integer类型字段的长尾长度?
- 内容介绍
- 文章标签
- 相关推荐
本文共计217个文字,预计阅读时间需要1分钟。
在Laravel数据库迁移中,当使用integer类型时无法指定长度。很多小伙伴在传递第二个参数后会出现迁移错误,如Syntax error or access violation: 1075 Incorrect table definition; there can be only one。这是因为MySQL不支持为integer类型指定长度。直接使用`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。
本文共计217个文字,预计阅读时间需要1分钟。
在Laravel数据库迁移中,当使用integer类型时无法指定长度。很多小伙伴在传递第二个参数后会出现迁移错误,如Syntax error or access violation: 1075 Incorrect table definition; there can be only one。这是因为MySQL不支持为integer类型指定长度。直接使用`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。

