Skip to content

An AlterColumn that Npgsql writes as drop and add takes an exclusion constraint with it, in silence #80

Closed

Description

@CaffeinatedCoder

Found by the analysis of #77 and #79, reproduced on PostgreSQL 16.15 and 18.6. Nothing is released.

What happens

Npgsql's generator writes DROP COLUMN and ADD COLUMN for an AlterColumnOperation whose ComputedColumnSql or IsStored differs from the old column's. The kernel maps every AlterColumnOperation to BaseChange.ColumnAltered, and the exclusion contributor answers Unaffected. PostgreSQL drops an exclusion constraint with a column that is one of its elements, without saying so.

Reproduction

Source: the scheduling model (GranteeId, RoleId, Period, a condition on RevokedOn, named). Target: the same, with GranteeId as HasComputedColumnSql("\"RoleId\" * 10", stored: true).

  • The diff is one AlterColumnOperation and nothing of SchemaKit's.
  • It applies. pg_constraint then holds no exclusion constraint.
  • EnsureCreated() of the target model has the constraint.
  • The target model against itself diffs to nothing, so no later migration puts it back.

The other direction (computed to plain) is the same. With the column in the condition only, the apply fails with 2BP01, which is loud.

Fix

BaseChanges has to say what the provider's statement does: where Npgsql drops and adds the column, the change is a ColumnDropped (or a case of its own), so that Lost and RebuildAround apply as for a drop. The plan's section 3.7 lists a computed column as not measured; 5.x had this as its issue 184. Check SQL Server's generator for the same.

Tests

Live: scheduling to the computed model leaves the catalog EnsureCreated() builds. Offline: the add stands after the column's operation. A test that holds the list of what makes Npgsql drop and add, against its generator, as RebuiltOnSqlite is held.

Activity

  1. added this to the 11.0.0 milestone on Nov 12, 2026
  2. added
    bug
    silent
    severity/high
    package/core
    on Nov 12, 2026
  3. added
    package/postgresql
    area/constraints
    area/migrations
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/constraintsarea/migrationsbugpackage/corepackage/postgresqlseverity/highsilent

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions