Skip to content

AutoMigration always attempts to set the default value, even when it hasn’t changed. #7553

@knight42

Description

@knight42

GORM Playground Link

go-gorm/playground#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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions