Repository navigation
Description
Found by a pre-release sweep of main @ 934ec55; reproduced in a scratch test.
Problem
ResolveIncludeList (CustomMigrationsModelDiffer.cs:698-707) resolves each INCLUDE entry as a property path and falls back to the entry verbatim (ResolveColumnName(...) ?? entry). When the property an entry named is removed from the model, the target resolves to the same text the source did. The descriptors are equal, and the index is left untouched.
Model: HasComplexIndex(x => x.Email.Value, ix => ix.HasName("ux_email").IsUnique().IncludeProperties("Note")). The next model adds b.Ignore(x => x.Note) and keeps the declaration. The whole migration is:
ALTER TABLE members DROP COLUMN "Note";
- PostgreSQL:
DROP COLUMNdrops every index that uses the column, INCLUDE columns included. The unique index disappears, the migration applies cleanly, and the snapshot still lists the index, so no later migration recreates it. - SQL Server: the same migration fails at apply (Msg 5074).
The same applies to a verbatim filter that names the removed column (not reproduced).
Change
Keep the documented verbatim fallback ("raw_col"), but in the target model check each fallback entry against the table's columns and throw from migrations add, naming the entry, when no such column exists. ColumnsReadBy already matches filter text against the table's columns and could cover the filter case. This changes an answer (a model that scaffolded now fails), so it belongs under ### Changed answers with a docs/upgrading.md entry.
Tests
NpgsqlDiff and SqlServerDiff tests: the model above throws InvalidOperationException naming Note. A test that "raw_col" naming a real column still passes.
Activity
CaffeinatedCoder commentedon Oct 20, 2026
Fixed for INCLUDE entries in #147. The filter case is not part of that PR.
Filter case. A verbatim filter that names a removed column (
filter: "\"Note\" IS NOT NULL") has the same shape: both sides carry the same text, no index operation is emitted, and on PostgreSQL theDROP COLUMNtakes the index with it.ColumnsReadBycan't cover it cleanly. It only checks which of the table's column names appear in the filter text, and that over-approximates. The check this case needs goes the other way: find a name the filter uses that is not a column. That means tokenizing SQL identifiers per provider (quoted"x"/[x]and unquoted ones, outside string literals), and telling columns apart from function names, keywords, casts and JSON path segments. A filter written with{Property}placeholders is already covered, because an unresolvable placeholder throws. Doing this for a verbatim filter needs its own design: either a quoted-identifier-only check, or steering users towards placeholders.