The Error
Microsoft.EntityFrameworkCore.Migrations: The model has pending changes. Add a new migration.
Quick Fix - 1 Minute
// Dev Fix: Generate and apply migration
// Package Manager Console:
Add-Migration FixPendingModelChanges
Update-Database
// Or CLI:
dotnet ef migrations add FixPendingModelChanges
dotnet ef database update
Why This Happens
EF Core detects your DbContext model doesn't match the last migration snapshot. Common after adding DbSet, changing properties, or switching branches. .NET 8 EF throws on startup if db.Database.Migrate() is called with pending changes.
Step-by-Step Debug
- Check what changed:
dotnet ef migrations list - If changes are wrong: delete last migration folder +
Remove-Migration - If changes are correct:
Add-Migration YourChangeName - Never edit migration files after
Update-Database- creates drift - For CI/CD: use
db.Database.Migrate()only after verifying migrations exist
No comments yet. Be the first to share your thoughts!