Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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})
}
like image 483
Alihossein shahabi Avatar asked May 25 '26 01:05

Alihossein shahabi


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.

like image 68
icza Avatar answered May 28 '26 09:05

icza