For more details, see blog post:
a pit about Golang variable scope
fix:
remove the colon from DB, err := gorm.open:
the original understanding was that golang would define the new variable err, DB was the global variable originally defined. But the reality is that for a variable defined with :=, if the new variable DB is not in scope with the same name as the defined variable (in this case, the global variable DB), then Golang defines the new variable DB to cover up the global variable DB, which is the real cause of the problem.
Read More:
- After the go pointer is declared and assigned, a panic: runtime error: invalid memory address or nil pointer reference appears
- panic: runtime error: index out of range
- Runtime error 5 Invalid procedure call or argument
- Go get github.com/kotakanbe/go -Problems encountered in CVE dictionary Download
- Error response from daemon: OCI runtime create failed: container_linux.go:380
- standard_init_linux.go:178: exec user process caused “no such file or directory”
- Error 945 Database cannot be opened due to inaccessible files or insufficient memory or disk space
- Free(): invalid pointer error when libtorch runs under Linux
- Error response from daemon: OCI runtime exec failed: exec failed: container_linux.go:345:
- Invalid column reference when using round in hive
- Failed to connect to non-global ctrl_ifname: (nil) error: No such file or directory (How to Fix)
- Eclipse startup error: a Java runtime environment (JRE) or Java Development Kit (JDK) must be available
- Fedora32 start container error – OCI runtime create failed: This version of runc doesn’t work on cgroups V2: unknown
- The difference, cause and solution of memory overflow and memory leak
- The @ Autowired annotation in springboot is invalid in ordinary classes. How to solve and use the null pointer exception java.lang.nullpointerexception
- In function `_start’ undefined reference to `main’ error: ld returned 1 exit status
- Idea pop-up window out of memory, modify the parameters and start the no response solution
- Springboot modifies the reference of the application.yml or. Properties file to report an error after startup
- [Solved] Memory analysis tool Start Error: An internal error occurred during: “Parsing heap dump from
- RuntimeError:cuda runtime error (11) : invalid argument at /pytorch/aten/src/THC/generic