当前位置:网站首页>使用gorm查询数据库时reflect: reflect.flag.mustBeAssignable using unaddressable value
使用gorm查询数据库时reflect: reflect.flag.mustBeAssignable using unaddressable value
2022-06-24 19:03:00 【russle】
使用gorm写了个小的demo, 插入和查询单个数据库都正确显示,在查询all数据是报错了。
错误信息
重点信息:using unaddressable value
reflect: reflect.flag.mustBeAssignable using unaddressable value
C:/F/yqgopath/pkg/mod/github.com/jinzhu/[email protected]/scope.go:865 (0xb197a6)
(*Scope).callCallbacks.func1: panic(err)
C:/F/Go/src/runtime/panic.go:679 (0x430b8f)
gopanic: reflectcall(nil, unsafe.Pointer(d.fn), deferArgs(d), uint32(d.siz), uint32(d.siz))
C:/F/Go/src/reflect/value.go:247 (0x48f54e)
flag.mustBeAssignableSlow: panic("reflect: " + methodName() + " using unaddressable value")
C:/F/Go/src/reflect/value.go:234 (0x4957f1)
flag.mustBeAssignable: f.mustBeAssignableSlow()
C:/F/Go/src/reflect/value.go:1531 (0x4957d8)
Value.Set: v.mustBeAssignable()
C:/F/yqgopath/pkg/mod/github.com/jinzhu/[email protected]/callback_query.go:48 (0xad949d)
queryCallback: results.Set(reflect.MakeSlice(results.Type(), 0, 0))
C:/F/yqgopath/pkg/mod/github.com/jinzhu/[email protected]/scope.go:869 (0xb03218)
(*Scope).callCallbacks: (*f)(scope)
C:/F/yqgopath/pkg/mod/github.com/jinzhu/[email protected]/main.go:354 (0xaf0e6e)
(*DB).Find: return s.NewScope(out).inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db
C:/F/GoLandProjects/mygotutorials/ginconfigdemo/pkg/controller/user_controller.go:57 (0xb40d30)
(*UserController).GetAllUsers: result := c.db.Find(users)
C:/F/yqgopath/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xa9bef1)
(*Context).Next: c.handlers[c.index](c)
C:/F/yqgopath/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:83 (0xab03ba)
RecoveryWithWriter.func1: c.Next()
C:/F/yqgopath/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xa9bef1)
(*Context).Next: c.handlers[c.index](c)
C:/F/yqgopath/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0xaaf4c7)
LoggerWithConfig.func1: c.Next()
C:/F/yqgopath/pkg/mod/github.com/gin-gonic/[email protected]/context.go:161 (0xa9bef1)
(*Context).Next: c.handlers[c.index](c)
C:/F/yqgopath/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:409 (0xaa6653)
(*Engine).handleHTTPRequest: c.Next()
C:/F/yqgopath/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:367 (0xaa5d44)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
C:/F/Go/src/net/http/server.go:2802 (0x76e1fa)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
C:/F/Go/src/net/http/server.go:1890 (0x7699cb)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
C:/F/Go/src/runtime/asm_amd64.s:1357 (0x45c1c0)
goexit: BYTE $0x90 // NOP
````
仔细对比发现就是查询传入的不是纸质
```go
users := make([]model.User, 0)
//这里有问题,一直无法查询全部内容,因为没有使用&users, 而是出入users
result := c.db.Find(&users)
if result.Error != nil {
klog.Infof("failed to find all, err:%s", result.Error)
}
错误信息截图
边栏推荐
- Ribbon源码分析之@LoadBalanced与LoadBalancerClient
- Coinbase will launch the first encryption derivative for individual investors
- Map跟object 的区别
- Byte and Tencent have also come to an end. How fragrant is this business of "making 30million yuan a month"?
- Redis error: -bash: redis cli: command not found
- [go Language brossage] go from 0 to Getting started 4: Advanced use of slice, Primary Review and Map Getting started Learning
- 二叉树的基本性质与遍历
- What is showcase? What should showcase pay attention to?
- Bytebase rejoint la communauté de base de données open source d'alicloud polardb
- OpenVINO2022 Dev Tools安装与使用
猜你喜欢

Test drive citus 11.0 beta (official blog)

What about the Golden Angel of thunder one? Golden Angel mission details

Information theory of popular science Shannon

【Go語言刷題篇】Go從0到入門4:切片的高級用法、初級複習與Map入門學習

Q1: error in JMeter filename must not be null or empty

Install the custom module into the system and use find in the independent project_ Package found
![[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map](/img/3a/db240deb4c66b219ef86f40d4c7b7d.png)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map

Stackoverflow 年度报告 2022:开发者最喜爱的数据库是什么?

Zadig + cave Iast: let safety dissolve in continuous delivery

苹果不差钱,但做内容“没底气”
随机推荐
JVM tuning
基于QT+MySQL的相机租赁管理系统
What is showcase? What should showcase pay attention to?
“拯救”直播带货,一个董宇辉还不够
Oracle create tablespaces and tables
实现基于Socket自定义的redis简单客户端
Apple, Microsoft and Google will no longer fight each other. They will work together to do a big thing this year
Openstack actual installation and deployment tutorial, openstack installation tutorial
Teach you how to view the number of connected people on WiFi in detail how to view the number of connected people on WiFi
开放可编程基础设施(OPI)项目,重新定义DPU/IPU
Predicate
JMeter environment deployment
unity之模糊背景(带你欣赏女人的朦胧美)
The name of the button in the Siyuan notes toolbar has changed to undefined. Has anyone ever encountered it?
图像PANR
天天鉴宝暴雷背后:拖欠数千万、APP停摆,创始人预谋跑路?
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map
Bytebase rejoint la communauté de base de données open source d'alicloud polardb
lol手游之任务进度条精准计算
顺序栈1.0版本