3 回答
TA贡献1831条经验 获得超10个赞
我在戈尔姆的问题中发现了这一点:
gorm.DefaultCallback.Create().Remove("mssql:set_identity_insert")
https://github.com/go-gorm/gorm/issues/941#issuecomment-250267125
TA贡献1836条经验 获得超5个赞
嵌入 gorm 总是更好。默认情况下提供字段的结构中的模型:ID、创建时、更新时、已删除。默认情况下,ID 将是主键,并且它是自动递增的(由 GORM 管理)
type MyStructure struct {
gorm.Model
SomeFlag bool `gorm:"not null"`
Name string `gorm:"type:varchar(60)"`
}
删除现有表:并再次创建表:,然后尝试插入记录。db.Migrator().DropTable(&MyStructure{})db.AutoMigrate(&MyStructure{})
TA贡献1809条经验 获得超8个赞
只需更换您的结构
type MyStructure struct {
ID int32 `gorm:"primaryKey;autoIncrement:true"`
SomeFlag bool `gorm:"not null"`
Name string `gorm:"type:varchar(60)"`
}
与此
type MyStructure struct {
ID int32 `gorm:"AUTO_INCREMENT;PRIMARY_KEY;not null"`
SomeFlag bool `gorm:"not null"`
Name string `gorm:"type:varchar(60)"`
}
- 3 回答
- 0 关注
- 311 浏览
添加回答
举报
