ERROR reflect.ValueOf(val).IsZero undefined (type reflect.Value has no field or method IsZero

Viewed 1951

I want to use gorm in my code but when I run go run *.go, I see this Error, unfortunately.

/var/www/html/src/gorm.io/gorm/utils/utils.go:46:30: reflect.ValueOf(val).IsZero undefined (type reflect.Value has no field or method IsZero)

this is my code:

package main

import (
    "gorm.io/gorm"
    "gorm.io/driver/sqlite"
)

type Product struct {
    gorm.Model
    Code  string
    Price uint
}

func main() {
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
if err != nil {
    panic("failed to connect database")
}

// Migrate the schema
db.AutoMigrate(&Product{})

// Create
db.Create(&Product{Code: "D42", Price: 100})
}
1 Answers

The Value.IsZero() method was added in Go 1.13. You have to use Go 1.13 or a later version if your code relies on this "feature".

You can check your go version by running go version.

Related