2

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})
}
3
  • Could you please share the stack trace for better understanding
    – Subinoy
    Commented Nov 10, 2020 at 17:26
  • 1
    Unrelated, but you should never be running a project with go run *.go. See golang.org/doc/code.html to get started.
    – JimB
    Commented Nov 10, 2020 at 21:46
  • @jimB thanks. Yes, but I just wanted to debug the code Commented Nov 10, 2020 at 21:48

1 Answer 1

4

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.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.