dotnet/efcore · warning · OperationException
Changes have been made to the model since the last migration
Error message
Changes have been made to the model since the last migration. Add a new migration.
What it means
HasPendingModelChanges detected that the current model differs from the last migration's model snapshot, i.e. you have unbilled model changes. This is thrown by 'dotnet ef migrations has-pending-model-changes' (used in CI guards) to signal non-zero exit. It is informational in nature but reported as an OperationException so the CLI exits non-zero.
Source
Thrown at src/EFCore.Design/Design/Internal/MigrationsOperations.cs:375
return files;
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual void HasPendingModelChanges(string? contextType)
{
using var context = _contextOperations.CreateContext(contextType);
var hasPendingModelChanges = context.Database.HasPendingModelChanges();
if (hasPendingModelChanges)
{
throw new OperationException(DesignStrings.PendingModelChanges);
}
_reporter.WriteInformation(DesignStrings.NoPendingModelChanges);
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[RequiresDynamicCode("Runtime migration compilation requires dynamic code generation.")]
public virtual MigrationFiles AddAndApplyMigration(
string name,
string? outputDir,
string? contextType,
string? @namespace,
string? connectionString)View on GitHub (pinned to dbf9771522)
Solutions
- Run 'dotnet ef migrations add <Name>' to capture the pending changes.
- If the changes are unintended, revert the model edit and rebuild.
- If a previous migration was applied but its snapshot is stale, regenerate the snapshot by adding an empty migration or hand-fixing ModelSnapshot.
- In CI, treat this exit code as a gate that requires a new migration commit.
Example fix
// before: CI fails because model changed entity.Property<string>(e => e.Status); // newly added // after dotnet ef migrations add AddOrderStatus
Defensive patterns
Strategy: try-catch
Validate before calling
bool hasPending = context.Database.HasPendingModelChanges();
if (hasPending) Console.Error.WriteLine("Model drift detected -- add a migration."); Try / catch
try { executor.HasPendingModelChanges(contextType); }
catch (OperationException ex) when (ex.Message.Contains("Changes have been made"))
{ /* CI gate: fail the build and prompt for a new migration */ Environment.ExitCode = 1; } Prevention
- Wire 'has-pending-model-changes' into CI as a required gate.
- Add migrations immediately after model changes, not in batches.
- Resolve snapshot conflicts during merges before pushing.
When it happens
Trigger: 'dotnet ef migrations has-pending-model-changes' runs HasPendingModelChanges() which returns true because entity/property/config changes since the last migration are not yet captured in a migration.
Common situations: CI pipeline checks for drift after a model edit; developer added an entity or property but forgot 'migrations add'; snapshot out of sync after a merge.
Related errors
- No DbContext named '{name}' was found.
- The wildcard '*' can only be used with commands that run for
- No DbContext was found in assembly '{assembly}'. Ensure that
- Failed to compile migration '{migrationId}'. Errors: {errors
- No ModelSnapshot was found.
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/7f44a87af7fa3189.
Report an issue: GitHub.