gorm icon indicating copy to clipboard operation
gorm copied to clipboard

migrator HasColumn will panic when the first parameter is a string

Open sishui opened this issue 2 years ago • 2 comments

GORM Playground Link

Database mysql, driver: gorm mysql

if migrator.HasColumn("TableName", "fieldName") {
	//...
}

panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x65b676]

goroutine 1 [running]:
gorm.io/gorm/migrator.Migrator.HasColumn.func1(0xc000324c40)
	D:/workspace/go/pkg/mod/gorm.io/[email protected]/migrator/migrator.go:372 +0xf6
gorm.io/gorm/migrator.Migrator.RunWithValue({{0x0, 0xc000311920, {0xa6ee60, 0xc000062ae0}}}, {0x90c620, 0xa51f70}, 0xc000115680)
	D:/workspace/go/pkg/mod/gorm.io/[email protected]/migrator/migrator.go:52 +0x2ae
gorm.io/gorm/migrator.Migrator.HasColumn({{0x0, 0xc000311920, {0xa6ee60, 0xc000062ae0}}}, {0x90c620, 0xa51f70}, {0x9c0201, 0x9})
	D:/workspace/go/pkg/mod/gorm.io/[email protected]/migrator/migrator.go:369 +0x194

migrator.go#L372 stmt.Schema is nil

The RenameColumn interface has similar issues

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x120bc12]

goroutine 1 [running]:
gorm.io/gorm/migrator.Migrator.RenameColumn.func1(0xc000163880)
	D:/workspace/go/pkg/mod/gorm.io/[email protected]/migrator/migrator.go:388 +0x92
gorm.io/gorm/migrator.Migrator.RunWithValue({{0x0, 0xc0002bec30, {0x161ee80, 0xc000062ae0}}}, {0x14bc620, 0xc0002d20b0}, 0xc000114d68)
	D:/workspace/go/pkg/mod/gorm.io/[email protected]/migrator/migrator.go:52 +0x2ae
gorm.io/gorm/migrator.Migrator.RenameColumn({{0x0, 0xc0002bec30, {0x161ee80, 0xc000062ae0}}}, {0x14bc620, 0xc0002d20b0}, {0x156c2b6, 0x7}, {0x156c285, 0x7})
	D:/workspace/go/pkg/mod/gorm.io/[email protected]/migrator/migrator.go:387 +0x145
gorm.io/driver/mysql.Migrator.RenameColumn.func1(0xc0001636c0)
	D:/workspace/go/pkg/mod/gorm.io/driver/[email protected]/migrator.go:59 +0x6c5
gorm.io/gorm/migrator.Migrator.RunWithValue({{0x0, 0xc0002bec30, {0x161ee80, 0xc000062ae0}}}, {0x14bc620, 0xc0002d20b0}, 0xc000115630)
	D:/workspace/go/pkg/mod/gorm.io/[email protected]/migrator/migrator.go:52 +0x2ae
gorm.io/driver/mysql.Migrator.RenameColumn({{{0x0, 0xc0002bec30, {0x161ee80, 0xc000062ae0}}}, {0xc000062ae0}}, {0x14bc620, 0xc0002d20b0}, {0x156c2b6, 0x7}, {0x156c285, ...})
	D:/workspace/go/pkg/mod/gorm.io/driver/[email protected]/migrator.go:57 +0x1b4

sishui avatar Oct 25 '22 09:10 sishui

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

github-actions[bot] avatar Oct 25 '22 09:10 github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

github-actions[bot] avatar Oct 26 '22 03:10 github-actions[bot]