Skip to content

fix(migrator): normalize DB-side "NULL" default to fix infinite AlterColumn loop on Postgres - #7806

Open
boobusy wants to merge 1 commit into
go-gorm:masterfrom
boobusy:fix/pg-default-null-alter-loop
Open

fix(migrator): normalize DB-side "NULL" default to fix infinite AlterColumn loop on Postgres#7806
boobusy wants to merge 1 commit into
go-gorm:masterfrom
boobusy:fix/pg-default-null-alter-loop

Conversation

@boobusy

@boobusy boobusy commented Jun 5, 2026

Copy link
Copy Markdown
  • Do only one thing
  • Non breaking API changes
  • Tested

Description

Normalize DB-side DEFAULT NULL literal to prevent infinite AlterColumn loop on PostgreSQL.

What did this pull request do?

  • Add !strings.EqualFold(dv, "NULL") to the first default value comparison case in MigrateColumn
  • Mirrors the existing model-side normalization where default:NULL tag is treated as no-default
  • Prevents AlterColumn from being triggered on every startup when a PostgreSQL column has DEFAULT NULL in its column_default catalog entry

User Case Description

PostgreSQL's information_schema.columns.column_default stores the literal string "NULL" for columns explicitly defined with DEFAULT NULL, while MySQL and other drivers return SQL NULL (empty) for the same semantic state.
GORM's MigrateColumn already normalizes the model side — default:NULL tag is treated as "no default" via EqualFold. But the DB side comparison was missing the same normalization, causing:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant