GORM Playground Link

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

Description

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.