当前位置:网站首页>记一个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
边栏推荐
- The ultra-large-scale industrial practical semantic segmentation dataset PSSL and pre-training model are open source!
- Redis 底层的数据结构
- nacos startup error, the database has been configured, stand-alone startup
- [Server data recovery] Data recovery case of server Raid5 array mdisk disk offline
- libcurl访问url保存为文件的简单示例
- leetcode/字符串中的变位词-s1字符串的某个排列是s2的子串
- ¶Backtop 回到顶部 不生效
- The characteristics and principle of typescript29 - enumeration type
- Redis 持久化 - RDB 与 AOF
- typeof in typescript32-ts
猜你喜欢

【 wheeled odometer 】

Constructor instance method inheritance of typescript38-class (implement)

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

2022 Henan Youth Training League Game (3)

Use baidu EasyDL implement factory workers smoking behavior recognition

"NetEase Internship" Weekly Diary (3)

2022-08-01 mysql/stoonedb slow SQL-Q18 analysis

Understand the big model in seconds | 3 steps to get AI to write a summary

手写博客平台~第二天

typescript32-ts中的typeof
随机推荐
How to adjust the cross cursor too small, CAD dream drawing calculation skills
"NetEase Internship" Weekly Diary (2)
Handwriting a blogging platform ~ Day 3
Redis Subscription and Redis Stream
Redis 底层的数据结构
搜罗汇总的效应
Golang分布式应用之Redis
AWR分析报告问题求助:SQL如何可以从哪几个方面优化?
【LeetCode每日一题】——654.最大二叉树
Hiring a WordPress Developer: 4 Practical Ways
软件测试功能测试全套常见面试题【开放性思维题】面试总结4-3
优炫数据库导库导错了能恢复吗?
swift项目,sqlcipher3 -> 4,无法打开旧版数据库有办法解决吗
typescript30-any类型
NIO‘s Sword(牛客多校赛)
Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021: Interpretation
oracle query scan full table and walk index
用位运算为你的程序加速
PHP uses PHPRedis and Predis
拼多多借力消博会推动国内农产品品牌升级 看齐国际精品农货