GORM Playground Link
https://github.com/go-gorm/playground/pull/1
Description
AutoMigration panic when add new column.
panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xf6dc70]
goroutine 1 [running]: database/sql.(ColumnType).Length(...) /usr/local/go/src/database/sql/sql.go:2993 gorm.io/gorm/migrator.ColumnType.Length(...) /go/pkg/mod/gorm.io/gorm@v1.23.3/migrator/column_type.go:67 gorm.io/gorm/migrator.Migrator.MigrateColumn(0xc0001ce501, 0xc00049e9f0, 0x173dc20, 0xc000132080, 0x1322160, 0xc0003b6690, 0xc0005f0f00, 0x1740460, 0xc0005a9450, 0xc00049e9f0, ...) /go/pkg/mod/gorm.io/gorm@v1.23.3/migrator/migrator.go:409 +0x12e gorm.io/driver/postgres.Migrator.MigrateColumn(0x1, 0xc00049e9f0, 0x173dc20, 0xc000132080, 0x1322160, 0xc0003b6690, 0xc0005f0f00, 0x1740460, 0xc0005a9450, 0x0, ...) /go/pkg/mod/gorm.io/driver/postgres@v1.3.3/migrator.go:205 +0x174 gorm.io/gorm/migrator.Migrator.AutoMigrate.func1(0xc00050c8c0, 0x1322160, 0xc0003b6690) /go/pkg/mod/gorm.io/gorm@v1.23.3/migrator/migrator.go:120 +0x7a8 gorm.io/gorm/migrator.Migrator.RunWithValue(0xc0005cd901, 0xc0006d2c00, 0x173dc20, 0xc000132080, 0x1322160, 0xc0003b6690, 0xc0008b39e8, 0x0, 0x0) /go/pkg/mod/gorm.io/gorm@v1.23.3/migrator/migrator.go:52 +0xd9 gorm.io/gorm/migrator.Migrator.AutoMigrate(0x1, 0xc0006d2c00, 0x173dc20, 0xc000132080, 0xc0005c8110, 0x1, 0x1, 0x0, 0x0) /go/pkg/mod/gorm.io/gorm@v1.23.3/migrator/migrator.go:101 +0x248 gorm.io/gorm.(DB).AutoMigrate(0xc000325200, 0xc0005c8110, 0x1, 0x1, 0x0, 0x0) /go/pkg/mod/gorm.io/gorm@v1.23.3/migrator.go:28 +0x5d gitlab.com/fin-delivery-back/models/migrations.MigrateAllData() /go/src/gitlab.com/fin-delivery-back/models/migrations/base.go:95 +0x937 main.main() /go/src/gitlab.com/fin-delivery-back/main.go:50 +0x285
Comment From: 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 ✨
Comment From: a631807682
upgrade postgres to v1.3.4
Comment From: 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 ✨
Comment From: asherascout
gorm version v1.23.5 gorm.io/driver/mysql version v1.3.3
I set autoMigration on select and I encountered same problem when I rundb.Table(tableName).Where(someFilters).Select(some fields).Find(&rows).
Seems that func (m Migrator) ColumnTypes works wrong.
for _, c := range rawColumnTypes {
if c.Name() == column.NameValue.String {
column.SQLColumnType = c
break
}
}
This code tries to match column names between rows and columns. However, when I using select, some columns are missing in rows, so SQLColumnType may be nil
Comment From: 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 ✨