Repository navigation
Drop a temporal foreign key before the base operations that need it gone (#187, #188) - #193
Merged
Merged
Conversation
… it gone Two base operations met a temporal foreign key the differ had left in place, and the migration failed at apply. A key whose dependent table the base operations drop was left to go with the table, also when its principal constraint was dropped or changed. That drop runs before the base operations, while the key still referenced it (2BP01, #187). The key is now dropped first whenever its principal constraint is dropped, changed or rebuilt. A key column's type changed on both tables: PostgreSQL re-checks the key after each ALTER COLUMN, and a GiST key has no cross-type operator, so a dependent altered before its principal failed (42804, #188). A type change on a key column on either side is now in the way of the key (RetypedColumns), so it is dropped before the base operations and added after. Closes #187 Closes #188 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…mporal-fk # Conflicts: # CLAUDE.md
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #187
Closes #188
Into
release/5.x. Both are temporal-FK ordering bugs inApplyTemporalConstraints, so they share one PR, as #167/#168 did.Closesacts only onmain, so both issues are closed by hand after the merge.Problem
Two base operations met a temporal foreign key that the differ had left in place, and the migration failed when it ran.
int→long). PostgreSQL re-checks the key after eachALTER COLUMN, and a GiST key has no cross-type operator. So whenever EF Core altered the dependent first, which depends on the table names, the migration failed.Change
In
NpgsqlComplexIndexMigrationsModelDiffer.ApplyTemporalConstraints:DependsOnChangedTemporalConstraint) or rebuilt (DependsOnRebuiltConstraint), as it already did for a dropped principal table. A table drop doesn't need the key, so dropping it first is always safe. The key still goes with its table when nothing else needs it gone.RetypedColumnscollects columns whoseColumnTypeorClrTypechanges. A key column, or a period, among them on either side puts the foreign key in the way, so it's dropped before the base operations and added after. This reuses the FK in-the-way rule PostgreSQL: changing a generated column's expression silently drops every complex index and constraint on it #184 introduced. The principal constraint's own index follows its column in place and isn't rebuilt.ReadsRecreatedColumnis renamedReadsAnyOf, since it now serves both sets.### Fixedlines in the root and PostgreSQL changelogs (both failed when they ran, so no database holds their result), two bullets indocs/postgresql-constraints.md(Change, remove or rename a constraint), and CLAUDE.md.Tests
TemporalForeignKeyOrderingTests(unit):ALTER COLUMNs and adds it after, without rebuilding the principal constraint.Dropping_dependent_table_and_principal_constraint_applies, with the dependent sorting first, as in the issue.Key_type_change_on_both_sides_applies, in both orders of the table names, with a row in each table. Afterwards the key exists and still rejects an orphan booking (23503).2BP01: cannot drop constraint AK_tk1_z_rooms_RoomId_ValidDuring …and42804: foreign key constraint "FK_tk2_z_bookings_tk2_a_rooms_RoomId_BookedDuring" cannot be implemented.🤖 Generated with Claude Code