当数据库里表不存在时,自动迁移可以正常运行。当数据库里表已经存在,新增字段或更改之前字段类型,会报错,错误如下: 2022/04/24 15:40:51 D:/Developement/go/pkg/mod/gorm.io/driver/postgres@v1.3.3/migrator.go:432 [1.000ms] [rows:-] SELECT a.attname as column_name, format_type(a.atttypid, a.atttypmod) AS data_type FROM pg_attribute a JOIN pg_class b ON a.attrelid = b.relfilenode AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = CURRENT_SCHEMA()) WHERE a.attnum > 0 -- hide internal columns AND NOT a.attisdropped -- hide deleted columns AND b.relname = 'bikes' panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x28 pc=0x8b5a96]

goroutine 1 [running]: database/sql.(ColumnType).DatabaseTypeName(...) E:/applications/Go/src/database/sql/sql.go:2950 gorm.io/gorm/migrator.ColumnType.DatabaseTypeName(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) D:/Developement/go/pkg/mod/gorm.io/gorm@v1.23.4/migrator/column_type.go:46 +0x126 gorm.io/driver/postgres.Migrator.AlterColumn.func1.1(0xc00009bda0, 0x1965ee0, 0xc000040150) D:/Developement/go/pkg/mod/gorm.io/driver/postgres@v1.3.3/migrator.go:253 +0x10d gorm.io/gorm.(DB).Connection(0xc000130de0, 0xc000665098, 0x0, 0x0) D:/Developement/go/pkg/mod/gorm.io/gorm@v1.23.4/finisher_api.go:539 +0x167 gorm.io/driver/postgres.Migrator.AlterColumn.func1(0xc00012a700, 0x153b2e0, 0xc0000ae000) D:/Developement/go/pkg/mod/gorm.io/gorm@v1.23.4/migrator/migrator.go:101 +0x26e gorm.io/gorm.(*DB).AutoMigrate(0xc0004348d0, 0xc0002be190, 0x1, 0x1, 0x0, 0x0) D:/Developement/go/pkg/mod/gorm.io/gorm@v1.23.4/migrator.go:28 +0x64 main.main() D:/Developement/go/src/bicycle/api/main.go:64 +0x3c7 exit status 2 make: *** [Makefile:21: run] Error 1

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 version

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