Your issue may already be reported! Please search on the issue track before creating one.
go version)?go1.11.1
mysql 8.0.13
package main
import (
"fmt"
)
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
type TParkRecord struct {
ID uint `gorm:"type:bigint(20) unsigned;not null;auto_increment;primary_key"`
ParkCode int `gorm:"type:bigint(10) unsigned;not null;default:'0'"`
}
func (t TParkRecord) TableName() string {
return "t_park_record"
}
func main() {
db, err := gorm.Open("mysql", "user:password@/dbname?charset=utf8&parseTime=True&loc=Local")
if err != nil {
fmt.Println(err)
}
defer db.Close()
db.LogMode(true)
db.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE = utf8_bin").AutoMigrate(&TParkRecord{})
}
when i run this code,i found auto increment doesn't work.

@jinzhu
please tell me what should i do?thx
@onecaffeine
璇峰儚杩欐牱瀹氫箟瀛楁
ID uint64 `gorm:"type:bigint(20) unsigned auto_increment;not null;primary_key"`
@baocaixiong
it works!!
why AUTO_INCREMENT is special for bigint ??
Seems this comment clarifies:
https://github.com/jinzhu/gorm/issues/201#issuecomment-52582868
@inliquid Thanks. I get it.
@baocaixiong thx,it works!!
For anyone else having issues, setting the type to serial worked for me.
``go
type User struct {
ID intgorm:"type: serial;"`
}
````
This sets the column default to the next sequential value:
"nextval('users_account_number_seq'::regclass)"
For anyone else having issues, setting the type to serial worked for me.
type User struct { ID int `gorm:"type: serial;"` }This sets the column default to the next sequential value:
"nextval('users_account_number_seq'::regclass)"
Works for me too!
Most helpful comment
@onecaffeine
璇峰儚杩欐牱瀹氫箟瀛楁