reflect.Value.Set using unaddressable value

golang reflect set value
reflect slice
reflect makeslice
reflect sliceheader
reflect map golang
golang reflect tags
golang addressable
golang reflect select
g.GET("/", func(c echo.Context) error {
    var users []models.User
    err := db.Find(users).Error
    if err != nil {
    return c.JSON(http.StatusOK, users)

this is the code for getting and displaying users from table using slice is resulting following error from gorm

reflect.Value.Set using unaddressable value

You have to call Find with a pointer to the slice.

err := db.Find(&users).Error

relevant Gorm documentation:

reflect: reflect.Value.Set using unaddressable value · Issue #83 , package main import ( "fmt" "" ) type P struct { X int64 Y int64 } func main() { vm := otto.New() vm.Set("GetPosition"  BUG REPORT INFORMATION Description We recently split our docker-compose.yml file into multiple yaml files and upgraded to v18.03 to take advantage of the added native support for this as per https:

Just to add clarification to S.Diego answers, changing this:

err := db.Find(users).Error

to this:

err := db.Find(&users).Error

the error says, the variable users is not addressable, because it is not a pointer.

panic: reflect: reflect.Value.Set using unaddressable value merging , panic: reflect: reflect.Value.Set using unaddressable value merging nested structures #90. Closed. luisdavim opened this issue on Nov 1, 2018 · 5 comments​. luisdavim changed the title [Question]: Override and append panic: reflect: reflect.Value.Set using unaddressable value merging nested structures Nov 3, 2018 Copy link Quote reply Author

In a very similar fashion to the accepted answer (but in a slightly different context), and an error that I keep making in different projects:

func migrate(db *gorm.DB) {
    db.AutoMigrate(User{}, Activity{})


func migrate(db *gorm.DB) {
    db.AutoMigrate(&User{}, &Activity{})

Notice the ampersands.

reflect.Value.Set using unaddressable value?, Developing an RPC client, not sure why but line 164 is returning a panic - "reflect.​Value.Set using unaddressable value". I am able to print the  reflect: reflect.Value.Set using unaddressable value #83. Closed fmzquant opened this issue Jun 22, 2014 · 2 comments Closed

The Go Playground, Set using unaddressable value // resultv.Set(reflect.Append(resultv, a)) } func main() { my := &My{} myType := reflect.TypeOf(my) slice := reflect.MakeSlice(​reflect. AutoMigrate: using unaddressable value #429. 16n opened this issue Mar 19, 2015 · 2 comments. Since updating to the newest version of go and gorm, I gate strange errors on AutoMigrate.

[SOLVED] Reflect func (Value) SetString, Hi everyone, Given the situation below, I got the following panic output: panic: reflect: reflect.flag.mustBeAssignable using unaddressable value  How do I append to a slice with reflect? reflect.Value.Set using unaddressable value Using reflect, how to set value to a struct field (pointer)

Chapter 12. Reflection, reflect.Value.Set using unaddressable value. Question. g.GET("/", func(c echo.​Context) error { var users []models.User err := db.Find(users).Error if err != nil { fmt​. Calling reflect.ValueOf on a value of array type gives you an array value, not a reference to an array value. You can't change an element of that array value any more than you can change the result of calling reflect.ValueOf on a number. Calling reflect.ValueOf on a value of slice type gives you a slice value, which includes a reference to an array. Changing an element of the slice means changing an element of the referenced array.

  • This is more generic thatn go-gorm. go-yaml's Unmarshal suffers the same issue when you pass it something that's not properly ampersanded. (Not the technical term, but it is what it is)
  • then i got a nil reference error i solved it by including driver
  • and create users slice before: users = make([]models.User,0)