Your Question
I've upgraded from gorm v1.22.3 to v1.24.2, but when I tried to insert an item using an "enum" byte/string gorm is trying to parse it to Uint, and it works 1.22.3.
The document you expected this should be explained
I've tried to replicate on playground but everything worked fine
https://github.com/go-gorm/playground/pull/547
This is the error I'm getting:
strconv.ParseUint: parsing \"draft\": invalid syntax
this is my enum:
type ProfileState byte
const (
ProfileStateDraft ProfileState = iota
ProfileStatePublished
)
var (
profileStates []ProfileState
profileStateToString = map[ProfileState]string{
ProfileStateDraft: "draft",
ProfileStatePublished: "published",
}
profileStateToID = map[string]ProfileState{
"draft": ProfileStateDraft,
"published": ProfileStatePublished,
}
)
func (ct ProfileState) String() string {
return profileStateToString[ct]
}
//Scan gorm scans the value in db and parse it to enum
func (ct *ProfileState) Scan(value interface{}) error {
var exists bool
*ct, exists = profileStateToID[value.(string)]
if !exists {
return errors.New("ProfileState scan: invalid value")
}
return nil
}
//Value gorm gets the value to store it in the db
func (rt ProfileState) Value() (driver.Value, error) {
return profileStateToString[rt], nil
}
Expected answer
How to solve this error.
Comment From: a631807682
I've tried to replicate on playground but everything worked fine
Neither can we replicate it, it might have something to do with not being recognized as SerializerInterface, issues closed until you can provide a reproduction.