当前位置:网站首页>记一个gorm初始化的坑
记一个gorm初始化的坑
2022-08-02 02:12:00 【不是住在隔壁的老王】
跨文件初始化gorm的时候,如果提前声明db *gorm.DB后在gorm.open的时候是用 db,err:= gorm.open的话 后续会报错
错误代码为:
panic: runtime error: invalid memory address or nil pointer dereference
将db,err := gorm.open改为
var err error
db,err = gorm.open
错误解决
解决思路来自博客:
http://t.csdn.cn/IxS0o
边栏推荐
- 求大神解答,这种 sql 应该怎么写?
- 【Unity入门计划】2D Game Kit:初步了解2D游戏组成
- The underlying data structure of Redis
- Day115.尚医通:后台用户管理:用户锁定解锁、详情、认证列表审批
- 编码经验之谈
- AI目标分割能力,无需绿幕即可实现快速视频抠图
- Rust P2P Network Application Combat-1 P2P Network Core Concepts and Ping Program
- Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读
- PHP uses PHPRedis and Predis
- YGG Guild Development Plan Season 1 Summary
猜你喜欢
LeetCode brush diary: LCP 03. Machine's adventure
Redis Subscription and Redis Stream
typescript31-any类型
【Unity入门计划】2D Game Kit:初步了解2D游戏组成
Check if IP or port is blocked
YGG Guild Development Plan Season 1 Summary
Handwriting a blogging platform ~ Day 3
oracle query scan full table and walk index
The underlying data structure of Redis
MySQL8 download, start, configure, verify
随机推荐
2022-07-30 mysql8执行慢SQL-Q17分析
[LeetCode Daily Question] - 103. Zigzag Level Order Traversal of Binary Tree
Redis Persistence - RDB and AOF
待读书单列表
2022-08-01 安装mysql监控工具phhMyAdmin
LeetCode brushing diary: 53, the largest sub-array and
MySQL optimization strategy
【LeetCode Daily Question】——704. Binary Search
typescript30 - any type
Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读
【ORB_SLAM2】void Frame::AssignFeaturesToGrid()
【LeetCode每日一题】——103.二叉树的锯齿形层序遍历
Can Youxuan database import wrongly be restored?
openGauss切换后state状态显示不对
6-25 Vulnerability Exploitation - irc Backdoor Exploitation
【 wheeled odometer 】
软件测试功能测试全套常见面试题【开放性思维题】面试总结4-3
6-24 exploit-vnc password cracking
Redis for distributed applications in Golang
Coding Experience Talk