Repository navigation
Description
Found while reviewing the SchemaKit design (#61); reproduced on main @ 8dfbf08 in a scratch MigrationHarness.NpgsqlDiff test.
Problem
When a column is renamed, every complex index and exclusion constraint on that column is dropped and created again. The database would have kept them: PostgreSQL and SQLite carry an index or constraint across a column rename, and SQL Server does unless the index's filter reads the column (sp_rename rejects that: "The index … is dependent on column …"). EF Core emits only the RenameColumnOperation for its own unfiltered indexes.
The differs compare resolved descriptors. The source side resolves to the old column name and the target side to the new one, so the pair never matches. Table renames are normalized (CustomMigrationsModelDiffer.cs:201, NpgsqlComplexIndexMigrationsModelDiffer.cs:1073). Column renames are not.
Model: members with HasColumnName("email") → "email_address" and "code" → "member_code". It has a unique HasComplexIndex(x => x.Email.Value), a composite index over both columns, and an exclusion constraint on Code.
CREATE EXTENSION IF NOT EXISTS btree_gist;
ALTER TABLE "members" DROP CONSTRAINT IF EXISTS "ex_members_code";
DROP INDEX ux_members_email;
DROP INDEX ix_members_code_email;
ALTER TABLE members RENAME COLUMN email TO email_address;
ALTER TABLE members RENAME COLUMN code TO member_code;
CREATE UNIQUE INDEX ux_members_email ON members (email_address);
CREATE INDEX ix_members_code_email ON members (member_code, email_address);
ALTER TABLE "members" DROP CONSTRAINT IF EXISTS "ex_members_code";
ALTER TABLE "members" ADD CONSTRAINT "ex_members_code" EXCLUDE USING gist ("member_code" WITH =, (int4range(1,2)) WITH &&);
The result is correct, but it costs a full rebuild. DROP INDEX and ADD CONSTRAINT … EXCLUDE take ACCESS EXCLUSIVE and hold it until commit. On a large table, a rename that should take milliseconds blocks reads and writes for as long as every index and constraint on the column takes to build.
Change
Resolve the source side under the target's column names for columns that a RenameColumnOperation in the base operations renames, as table renames already do. That covers column parts, JSON extractions (the container column), template and filter placeholders, INCLUDE lists, and exclusion and temporal elements. A pair that matches after normalization produces no operation.
This changes what an existing model scaffolds, so it ships in a minor with a ### Changed answers row and a docs/upgrading.md entry.
SchemaKit needs the same rule: design/schemakit-api.md §9.4 names table renames only.
Tests
- A
MigrationHarness.NpgsqlDifftest for the model above: only the twoRenameColumnOperations, no index or constraint operations. - The same on SQL Server and SQLite through
CoreDiff/SqlServerDiff. - A filter whose placeholder names the renamed column, and an INCLUDE entry naming it.
- A
PostgresIntegrationTestscase that applies the rename and reads the index definition back frompg_indexes.
Activity
fix: on SQL Server, rebuild a filtered index around a rename of a col…
Merge pull request #183 from CaffeinatedCoder/fix/182-column-renames
CaffeinatedCoder commentedon Oct 23, 2026
Fixed on release/5.x by #183 (merge d28c938), shipping in 5.6.0. Closed by hand:
Closesacts only on merges intomain.A column rename now keeps the complex indexes, exclusion constraints and temporal constraints on the column, and a default name that follows the column becomes a rename. SQL Server is the exception for filtered indexes:
sp_renamerejects a column a filtered index's predicate reads, so such an index is dropped before the rename and created after it, as EF Core does for its own.SchemaKit still needs the same rule:
design/schemakit-api.md§9.4 covers table renames only.docs: carry the column-rename rule into the SchemaKit design (#182)