当前位置:网站首页>记一个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
边栏推荐
- Day115. Shangyitong: Background user management: user lock and unlock, details, authentication list approval
- Ask God to answer, how should this kind of sql be written?
- 3. Bean scope and life cycle
- Redis 订阅与 Redis Stream
- 用位运算为你的程序加速
- Speed up your programs with bitwise operations
- 【 wheeled odometer 】
- The characteristics and principle of typescript29 - enumeration type
- LeetCode刷题日记:74. 搜索二维矩阵
- LeetCode Review Diary: 34. Find the first and last position of an element in a sorted array
猜你喜欢

Constructor instance method inheritance of typescript37-class (extends)

Data transfer at the data link layer

Day116.尚医通:预约挂号详情 ※

The characteristics and principle of typescript29 - enumeration type

Ringtone 1161. Maximum In-Layer Elements and

6-24 exploit-vnc password cracking

AWR分析报告问题求助:SQL如何可以从哪几个方面优化?

Basic use of typescript34-class

【Unity入门计划】2D Game Kit:初步了解2D游戏组成

MySQL optimization strategy
随机推荐
LeetCode brush diary: LCP 03. Machine's adventure
From 2023 onwards, these regions will be able to obtain a certificate with a score lower than 45 in the soft examination.
乱七八糟的网站
Personal blog system project test
LeetCode刷题日记:34、 在排序数组中查找元素的第一个和最后一个位置
Redis 订阅与 Redis Stream
typescript32-ts中的typeof
Named parameter implementation of JDBC PreparedStatement
Pinduoduo leverages the consumer expo to promote the upgrading of domestic agricultural products brands and keep pace with international high-quality agricultural products
openGauss切换后state状态显示不对
Constructor of typescript35-class
待读书单列表
[LeetCode Daily Question]——654. The largest binary tree
nacos启动报错,已配置数据库,单机启动
云和恩墨:让商业数据库时代的价值在openGauss生态上持续繁荣
编码经验之谈
AI目标分割能力,无需绿幕即可实现快速视频抠图
LeetCode brushing diary: 33. Search and rotate sorted array
十字光标太小怎么调节、CAD梦想画图算量技巧
『网易实习』周记(三)