Skip to content

Dropping both tables of a temporal foreign key fails when the principal sorts first, Down() included #79

Closed

Description

@CaffeinatedCoder

Problem

When a migration drops both the principal table of a temporal foreign key and its dependent table, the FK drop is skipped (the dependent table is being dropped anyway), and EF orders the DropTable operations without knowing about the temporal FK. If the principal sorts first, the migration fails:

model: a_rooms (HasTemporalConstraint) ← b_bookings (HasTemporalForeignKey to a_rooms)
diff to a model without both:
  DROP TABLE a_rooms;      -- 2BP01 cannot drop table a_rooms because other objects depend on it
  DROP TABLE b_bookings;

The Down() of the migration that created the two tables has the same shape, so dotnet ef database update <previous> and migrations remove after applying cannot roll back. Whether it fails depends only on the table names.

Cause: ApplyTemporalConstraints drops a temporal FK only when its dependent table survives (pendingForeignKeyDrops).

Fix

Emit the FK drop before the base operations whenever the principal table is dropped, even if the dependent is dropped too. Test: diff the model above to an empty model, assert a DropForeignKeyOperation precedes the first DropTableOperation, and apply it in PostgresIntegrationTests.

Loud. Found by the 5.5.0 pre-tag analysis; present since temporal FKs shipped.

Activity

  1. added this to the 5.5.1 milestone on Oct 19, 2026
  2. added
    bug
    severity/medium
    package/postgresql
    area/constraints
    area/migrations
    on Oct 19, 2026
  3. modified the milestones: 5.5.1, 5.5.0 on Oct 20, 2026
  4. added a commit that references this issue on Oct 20, 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/postgresqlseverity/medium

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions