100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C#

Handling Schema Drift in Teams

Strategies for detecting and resolving mismatches between the EF Core model, migration history, and the actual database schema across a team.

MigrationsAdvanced10 min readJul 10, 2026
Analogies

What Causes Schema Drift

Schema drift happens when the actual database schema diverges from what the migration history says it should be — caused by a developer manually altering a table in SQL Server Management Studio, an emergency hotfix applied directly to production during an incident, or two developers each adding a migration from the same parent snapshot and merging their branches without regenerating a unified migration. Because migrations add diffs the current model against the ModelSnapshot, not the live database, drift is invisible to EF Core until a migration fails to apply or produces incorrect SQL against a database that doesn't match what history claims.

🏏

Cricket analogy: It's like a groundsman quietly relaying a section of pitch overnight without updating the official pitch report — the next day's match officials work from a report that no longer matches reality.

Detecting Drift

Comparing the output of dotnet ef migrations script against the actual database schema using a schema-diff tool can reveal discrepancies, but a more reliable habit for teams is running dotnet ef migrations has-pending-model-changes — available from EF Core 8 onward — as a CI step that fails the build whenever the current model and the latest migration are out of sync, catching the problem before it ever reaches a shared database.

🏏

Cricket analogy: It's like a match referee cross-checking the official pitch report against an independent groundsman's inspection before play starts, catching any unauthorized relaying before the first ball is bowled.

yaml
# CI step (GitHub Actions) that fails the build if the model and migrations are out of sync
- name: Check for pending model changes
  run: dotnet ef migrations has-pending-model-changes --project src/MyApp.Data
  # Exits non-zero if OnModelCreating changes weren't captured in a migration

Resolving Merge Conflicts in Migrations

When two branches each add a migration against the same parent ModelSnapshot, merging both introduces duplicate or conflicting edits to ModelSnapshot.cs. The standard fix is to remove one branch's migration with dotnet ef migrations remove, rebase that branch onto the other branch's now-merged migration, and regenerate a fresh migration from the updated baseline — producing a single linear history with one consistent snapshot state rather than two competing ones.

🏏

Cricket analogy: It's like two separate committees independently amending the same rulebook clause from the same starting edition — the fix is to accept one committee's amendment as official, then have the second committee redraft theirs against that new baseline.

Never manually hand-edit ModelSnapshot.cs to resolve a merge conflict. Because it's a generated, self-consistent serialization of the entire model, hand-edited inconsistencies are extremely difficult to spot and can cause silent, incorrect diffs in future migrations. Always resolve conflicts by removing and regenerating migrations, letting the EF Core tooling produce a fresh, consistent snapshot.

  • Schema drift is a mismatch between the real database schema and what the migration history/ModelSnapshot says it should be.
  • Manual database changes and unmerged parallel migrations are the two most common causes of drift.
  • Drift is invisible to EF Core because migrations diff against the snapshot, not the live database.
  • dotnet ef migrations has-pending-model-changes (EF Core 8+) can catch model/migration mismatches in CI.
  • Merge conflicts in migrations should be resolved by removing and regenerating, never by hand-editing ModelSnapshot.cs.
  • A single linear migration history with one consistent snapshot state is essential for team collaboration.

Practice what you learned

Was this page helpful?

Topics covered

#EntityFrameworkCoreStudyNotes#MicrosoftTechnologies#HandlingSchemaDriftInTeams#Handling#Schema#Drift#Teams#SQL#StudyNotes#SkillVeris