Skip to content

db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kernelpod opened this issue May 7, 2025 · 1 comment
Open

db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) #170

kernelpod opened this issue May 7, 2025 · 1 comment
Assignees

Comments

@kernelpod
Copy link

runtime error: invalid memory address or nil pointer dereference,runtime error: invalid memory address or nil pointer dereference

runtime error: invalid memory address or nil pointer dereference

runtime error: invalid memory address or nil pointer dereference C:/src/runtime/panic.go:262 (0x3a3337) panicmem: panic(memoryError) C:/src/runtime/signal_windows.go:401 (0x3a3307) sigpanic: panicmem() C:/pkg/mod/gorm.io/gorm@v1.26.0/gorm.go:418 (0x522492) (*DB).getInstance: if db.clone > 0 { C:/pkg/mod/gorm.io/gorm@v1.26.0/chainable_api.go:113 (0x51c471) (*DB).Select: tx = db.getInstance() C:/pkg/User.go:20 (0x651bad) CheckUser: db.Select("id").Where("username = ?", name).First(&user) C:/pkg/user.go:18 (0x7b3504) AddUser: code = model.CheckUser(data.Username) C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/context.go:185 (0x7ad5ce) (*Context).Next: c.handlers[c.index](c) C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/recovery.go:102 (0x7ad5bb) CustomRecoveryWithWriter.func1: c.Next() C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/context.go:185 (0x7ac704) (*Context).Next: c.handlers[c.index](c) C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/logger.go:249 (0x7ac6eb) LoggerWithConfig.func1: c.Next() C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/context.go:185 (0x7abb51) (*Context).Next: c.handlers[c.index](c) C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/gin.go:633 (0x7ab5e0) (*Engine).handleHTTPRequest: c.Next() C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/gin.go:589 (0x7ab269) (*Engine).ServeHTTP: engine.handleHTTPRequest(c) C:/src/net/http/server.go:3301 (0x6a0a0d) serverHandler.ServeHTTP: handler.ServeHTTP(rw, req) C:/src/net/http/server.go:2102 (0x696a44) (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req) C:/src/runtime/asm_amd64.s:1700 (0x3c7180) goexit: BYTE $0x90 // NOP

Expected answer

db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}
change
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{}
that's ok
Is this a bug? Or is there something wrong with the code I wrote?

@kernelpod
Copy link
Author

The official website document is written like this, and the test still does not work when compared with the example given on the official website. The problem here is pointed out through the cursor.

go 1.24.2

require (
github.com/gin-gonic/gin v1.10.0
gorm.io/gorm v1.26.0
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants