go-gorm / postgres

GORM PostgreSQL driver
MIT License
234 stars 123 forks source link

fail to alter column #104

Closed warren830 closed 2 years ago

warren830 commented 2 years ago

GORM Playground Link

https://github.com/go-gorm/playground/pull/475

Description

If we want to change column from varchar to int, it will report error like below: [2022-05-09 11:57:51] INFO [db] /opt/homebrew/Cellar/go@1.17/1.17.9/pkg/mod/gorm.io/driver/postgres@v1.3.5/migrator.go:270 ERROR: column "xxx" cannot be cast automatically to type bigint (SQLSTATE 42804) [1.840ms] [rows:0] ALTER TABLE "xxx" ALTER COLUMN "xxx" TYPE bigint

We only need to append USING xxx::bigint in func AlterColumn in postgres@v1.3.5/migrator.go

williamluisan commented 2 years ago

Still broken when change from int to uuid data type. ERROR: column "BookingId" cannot be cast automatically to type uuid (SQLSTATE 42804)