Skip to content

SQL Server: a renamed complex index stays in the way of ALTER COLUMN, and the migration fails at apply (Msg 5074) #141

Closed

Description

@CaffeinatedCoder

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.

Activity

  1. added this to the 5.5.0 milestone on Oct 20, 2026
  2. added
    bug
    severity/high
    package/core
    package/sqlserver
    on Oct 20, 2026
  3. added
    area/indexes
    area/migrations
    on Oct 20, 2026
  4. added 2 commits that reference 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/indexesarea/migrationsbugpackage/corepackage/sqlserverseverity/high

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions