当前位置:网站首页>使用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)
}
错误信息截图
边栏推荐
- 二叉树的基本性质与遍历
- Redis error: -bash: redis cli: command not found
- 【建议收藏】时间序列预测应用、paper汇总
- CVPR 2022缅怀孙剑!同济、阿里获最佳学生论文奖,何恺明入围
- Huawei cloud modelarts has ranked first in China's machine learning public cloud service market for the fourth time!
- Bytebase rejoint la communauté de base de données open source d'alicloud polardb
- 【CANN文档速递04期】揭秘昇腾CANN算子开发
- Ribbon source code analysis @loadbalanced and loadbalancerclient
- DX12引擎开发课程进度-这个课程到底讲到哪里了
- 【CANN文档速递06期】初识TBE DSL算子开发
猜你喜欢
“拯救”直播带货,一个董宇辉还不够
16 excellent business process management tools
[video tutorial] functions that need to be turned off in win10 system. How to turn off the privacy option in win10 computer
顺序栈1.0版本
Fundamentals of performance testing -- definitions of common terms
Map跟object 的区别
苹果不差钱,但做内容“没底气”
Write a positive integer to the node and return a floating-point number multiplied by 0.85 when reading the node
《梦华录》“超点”,鹅被骂冤吗?
Bytebase joins Alibaba cloud polardb open source database community
随机推荐
Install the custom module into the system and use find in the independent project_ Package found
Anti epidemic through science and technology: white paper on network insight and practice of operators | cloud sharing library No.20 recommendation
Hosting service and SASE, enjoy the integration of network and security | phase I review
Where are Xiaomi mobile phone's favorite SMS and how to delete them
Microsoft Office Excel 2013 2016 graphic tutorial on how to enable macro function
Wait for the victory of the party! After mining ebb tide, graphics card prices plummeted across the board
[video tutorial] functions that need to be turned off in win10 system. How to turn off the privacy option in win10 computer
What are the functions of IBPs open source form designer?
gateway
Win7 10 tips for installing Office2010 five solutions for installing MSXML components
建立自己的网站(14)
Nodered has no return value after successfully inserting into the database (the request cannot be ended)
Openstack actual installation and deployment tutorial, openstack installation tutorial
【云驻共创】ModelBox隔空作画 绘制你的专属画作
Cooking business experience of young people: bloggers are busy selling classes and bringing goods, and the organization earns millions a month
First understand redis' data structure - string
UART communication (STM32F103 library function)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map
JMeter environment deployment
Some ideas about chaos Engineering