You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a table definition goes like the following:
type Payload struct {
ID string
}
type Table struct {
ID string `gorm:"primaryKey;type:uuid"`
Payload Payload `gorm:"serializer:json;type:jsonb;default:'{}'"`
}
We noticed that every time we run the auto migration, GORM always executes the SQL ALTER TABLE <table> ALTER COLUMN payload SET DEFAULT '{}' to set the default value, even though it hasn’t changed.
After some investigation, I found that GORM interprets the default value as '{}' when parsing the struct, but retrieves it as {} from the online database. This mismatch causes GORM to attempt to update the default value every time, even when it hasn’t changed.