GORM Playground Link
https://github.com/go-gorm/playground/pull/508
Description
Scenario:
- Migrate table (Make sure the struct has some
gotype offloat64data. - Create a View
- Re-Run Migrations
Expected Result:
All steps complete successfully
Result Achieved
The migrations in step 3 fail.
ERROR: cannot alter type of a column used by a view or rule (SQLSTATE 0A000)
The alteration shouldn't be necessary given the struct hasn't changed at all.
In one case I found out this was because it was converting a column that was numeric to decimal and failing to do so.
steps to get around:
The tests will pass if you specify a particular postgres type to the data like so:
type User struct {
gorm.Model
Name string
Age uint
Birthday *time.Time
Account Account
Pets []*Pet
Toys []Toy `gorm:"polymorphic:Owner"`
CompanyID *int
Company Company
ManagerID *uint
Manager *User
Team []User `gorm:"foreignkey:ManagerID"`
Languages []Language `gorm:"many2many:UserSpeak"`
Friends []*User `gorm:"many2many:user_friends"`
Active bool
TestValue float64 `gorm:"type:numeric"`
}
Comment From: emilhakobian
Any updates on this issue? I experience the same problem. After recent update to the latest version of gorm.
Comment From: emilhakobian
Solved when describing aliases explicitly. -- pgsql smallint <-> int2 integer <-> int4 bigint <-> int8 decimal <-> numeric
Source: https://github.com/go-gorm/gorm/pull/5627#issue-1344124013
Comment From: a631807682
https://github.com/go-gorm/gorm/pull/5627