The Error
System.InvalidOperationException: The model has pending changes. Add a new migration or remove existing migrations.Quick Fix - 1 Minute
# Package Manager Console
Add-Migration AddUserPhoneNumber
Update-Database
Or CLI
dotnet ef migrations add AddUserPhoneNumber
dotnet ef database update
Why This Happens
You changed DbContext or entity classes but didn't create a migration. EF detects model ≠ database schema at startup and throws. Happens after adding properties, DbSet, or changing types.
Best Practice for.NET 8
- Check what changed: dotnet ef migrations has-pending-model-changes
- If intentional: Add-Migration NameHere
- If mistake: Revert model changes or Remove-Migration
- Prod: Never auto-migrate. Generate SQL: dotnet ef migrations script
No comments yet. Be the first to share your thoughts!