Skip to content
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

使用 dbresolver 后,db.AutoMigrate 会访问到空指针 #102

Open
hackersean opened this issue Apr 13, 2023 · 0 comments
Open

使用 dbresolver 后,db.AutoMigrate 会访问到空指针 #102

hackersean opened this issue Apr 13, 2023 · 0 comments
Assignees

Comments

@hackersean
Copy link

我后面使用TiDB,可直接连接多个地址,所以使用了 dbresolver。
在创建gorm时,发现使用了一个nil的gorm.Dialector。后面db.AutoMigrate 就会读到空指针。
请问这里 gorm.Open 是必须要传入一个正确的链接么?后面不是已经使用了dbresolver了吗?
辛苦解答一下,谢谢。

db, err := gorm.Open(nil, &gorm.Config{})
	if err != nil {
		return err
	}

err = db.Use(dbresolver.Register(dbresolver.Config{Sources: dias, Policy: dbresolver.RandomPolicy{}}))
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x8a46aa]

goroutine 1 [running]:
gorm.io/gorm.(*DB).Migrator(0x40f227?)
        /home/sean/code/go/pkg/mod/gorm.io/gorm@v1.24.7-0.20230306060331-85eaf9eeda11/migrator.go:23 +0xaa
gorm.io/gorm.(*DB).AutoMigrate(0xc000517d40?, {0xc00050fb50, 0x1, 0x1})
        /home/sean/code/go/pkg/mod/gorm.io/gorm@v1.24.7-0.20230306060331-85eaf9eeda11/migrator.go:28 +0x28
gitee.com/pingcap_enterprise/tidb-enterprise-manager/pkg/storage.AutoMigrate(...)
        /home/sean/code/src/gitee.com/pingcap_enterprise/tidb-enterprise-manager/pkg/storage/init.go:58
gitee.com/pingcap_enterprise/tidb-enterprise-manager/pkg/storage.InitStorage(0xc00013e130)
        /home/sean/code/src/gitee.com/pingcap_enterprise/tidb-enterprise-manager/pkg/storage/init.go:50 +0x2dd
main.initialize()
        /home/sean/code/src/gitee.com/pingcap_enterprise/tidb-enterprise-manager/cmd/apiserver/main.go:55 +0x1d0
main.main()
        /home/sean/code/src/gitee.com/pingcap_enterprise/tidb-enterprise-manager/cmd/apiserver/main.go:64 +0x1d
exit status 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants