You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SQL Server: a renamed complex index stays in the way of ALTER COLUMN, and the migration fails at apply (Msg 5074) #141
area/indexesComplex-property, composite, unique and filtered indexesarea/migrationsThe differs, snapshot format, EnsureCreated and design-time wiringbugSomething isn't workingpackage/coreAffects EFCore.ComplexIndexespackage/sqlserverAffects EFCore.ComplexIndexes.SqlServerseverity/highWrong results, crash or failed writes in a realistic scenario
Found by a pre-release sweep of main @ 934ec55; reproduced in a scratch test.
Problem
A rename pair is neither a kept index nor a drop, so the "unchanged index in the way of a base operation" step (CustomMigrationsModelDiffer.cs:209-227) never sees it. Index renames are placed after the base operations ([.. drops, .. rebuildCreates, .. operations, .. renames, .. creates], :309), so on SQL Server the column under a renamed index is altered while the index still exists. The migration scaffolds cleanly and fails at apply with Msg 5074.
Model: table members → users, Email.Value max length 200 → 100, unique HasComplexIndex(x => x.Email.Value, isUnique: true) with its default name (which changes with the table, so the pair becomes a rename). An explicit rename (ux_members_email → ux_members_mail) together with the same length change does the same.
EXEC sp_rename N'[members]', N'users', 'OBJECT';
ALTER TABLE [users] ALTER COLUMN [Email_Value] nvarchar(100) NOT NULL; -- Msg 5074
EXEC sp_rename N'[users].[IX_members_Email_Value]', N'IX_users_Email_Value', 'INDEX';
Change
Run the in-the-way check over rename pairs too. A pair whose index is in the way becomes a drop under the old name (before the base operations) and a create under the new name (after them).
Tests
A MigrationHarness.SqlServerDiff test: no RenameIndexOperation after the AlterColumnOperation, and DropIndexOperation IX_members_Email_Value before it. Plus a SqlServerIntegrationTests case that applies the migration.
area/indexesComplex-property, composite, unique and filtered indexesarea/migrationsThe differs, snapshot format, EnsureCreated and design-time wiringbugSomething isn't workingpackage/coreAffects EFCore.ComplexIndexespackage/sqlserverAffects EFCore.ComplexIndexes.SqlServerseverity/highWrong results, crash or failed writes in a realistic scenario
Activity
Merge pull request #148 from CaffeinatedCoder/fix/141-143-rename-plac…
docs: carry the column-rename rule into the SchemaKit design (#182)