Never use RenameColumn while old and new app versions overlap: the old version would query a column that no longer exists. Use expand and contract over several releases. 1. Expand: add the new column (nullable). 2. Dual write: release an app version that writes both columns in the same SaveChanges (same transaction), or add a trigger that copies writes made by the old version, and still reads the old column. 3. Backfill existing rows in small batches (UPDATE TOP (5000) ... WHERE New IS NULL) to avoid long locks and log growth, then verify with a count of mismatches. 4. Switch reads to the new column; keep writing both so a rollback to the previous version still works. 5. Contract: once no running version uses the old column, stop writing it and drop it in a later migration. Each step is backward compatible with the version before it.
"During a rolling or slot-swap deployment both versions run against the same database, so every schema change must work with both. A rename can't: the moment the column is renamed, the old version's queries fail. So I split it into expand, migrate, contract.
Release 1 adds
EmailAddressas nullable and ships code that writes bothEmailAddressin the sameSaveChanges, so both are in one transaction and can't drift, but it still readsSELECT COUNT(*) WHERE Email <> EmailAddress OR EmailAddress IS NULLis zero, and make the column NOT NULL if needed.Release 2 reads
EmailAddressand still writes both, so rolling back to release 1 is safe. Release 3 stops writing
| Release | Schema | Writes | Reads | Safe rollback to |
|---|---|---|---|---|
| 1 | Add EmailAddress (nullable) |
Both | Email |
Previous |
| Backfill | Batched copy, verify | — | — | — |
| 2 | (Optional NOT NULL) | Both | EmailAddress |
1 |
| 3 | — | EmailAddress |
EmailAddress |
2 |
| 4 | Drop Email |
— | — | 3 |
WHILE 1 = 1
BEGIN
UPDATE TOP (5000) dbo.Customers SET EmailAddress = Email WHERE EmailAddress IS NULL;
IF @@ROWCOUNT = 0 BREAK;
WAITFOR DELAY '00:00:01';
END
A one-step rename on a [12 million]-row table broke [the old App Service slot] for [6 minutes] during a swap; the expand and contract version of the next rename shipped over three releases with zero errors.
Checks expand/contract thinking.
Last updated 23 Nov 2026.