dotnet/efcore · error · OperationException
No ModelSnapshot was found.
Error message
No ModelSnapshot was found.
What it means
`RemoveMigration` reads `Dependencies.MigrationsAssembly.ModelSnapshot`; when that property is `null` (no class deriving from `ModelSnapshot` is present in the migrations assembly) it throws `OperationException(NoSnapshot)`. The snapshot is what `RemoveMigration` rewrites to roll the model back, so without it the operation cannot proceed.
Source
Thrown at src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs:256
/// <param name="force">Revert the migration if it has been applied to the database.</param>
/// <param name="language">The project's language.</param>
/// <param name="dryRun">If <see langword="true" />, then nothing is actually written to disk.</param>
/// <param name="offline">Remove the migration without connecting to the database.</param>
/// <returns>The removed migration files.</returns>
public virtual MigrationFiles RemoveMigration(
string projectDir,
string? rootNamespace,
bool force,
string? language,
bool dryRun = false,
bool offline = false)
{
var files = new MigrationFiles();
var modelSnapshot = Dependencies.MigrationsAssembly.ModelSnapshot;
if (modelSnapshot == null)
{
throw new OperationException(DesignStrings.NoSnapshot);
}
var codeGenerator = Dependencies.MigrationsCodeGeneratorSelector.Select(language);
IModel? model = null;
var migrations = Dependencies.MigrationsAssembly.Migrations
.Select(m => Dependencies.MigrationsAssembly.CreateMigration(m.Value, _activeProvider))
.ToList();
if (migrations.Count != 0)
{
var migration = migrations[^1];
model = Dependencies.SnapshotModelProcessor.Process(migration.TargetModel);
if (!Dependencies.MigrationsModelDiffer.HasDifferences(
model.GetRelationalModel(),
Dependencies.SnapshotModelProcessor.Process(modelSnapshot.Model, resetVersion: true).GetRelationalModel()))
{
var applied = false;View on GitHub (pinned to dbf9771522)
Solutions
- Re-add a migration (`dotnet ef migrations add <Name>`) to regenerate the snapshot, then retry the remove.
- Check that `MigrationsAssembly` is configured to the assembly that actually holds your migration classes.
- Restore the deleted `*ModelSnapshot.cs` from source control.
Example fix
// before dotnet ef migrations remove // no ModelSnapshot present // after dotnet ef migrations add RestoreSnapshot // regenerates ModelSnapshot dotnet ef migrations remove
Defensive patterns
Strategy: validation
Validate before calling
// Ensure a ModelSnapshot exists before calling RemoveMigration.
var migrationsAssembly = serviceProvider
.GetRequiredService<Microsoft.EntityFrameworkCore.Migrations.IMigrationsAssembly>();
if (migrationsAssembly.ModelSnapshot is null)
throw new InvalidOperationException(
"No ModelSnapshot found. Re-add a migration to regenerate it before removing.");
scaffolder.RemoveMigration(projectDir, rootNamespace, force: false); Prevention
- Never delete `*ModelSnapshot.cs` by hand; use `dotnet ef migrations remove`.
- Keep `MigrationsAssembly` configured to the assembly holding your migrations.
- Commit the snapshot file alongside every migration so source control never drops it.
When it happens
Trigger: `dotnet ef migrations remove` (or `MigrationsScaffolder.RemoveMigration(...)`) when the migrations assembly contains no `*ModelSnapshot` class — e.g. the snapshot file was manually deleted, the project was set up without ever producing one, or `MigrationsAssembly` points at the wrong assembly.
Common situations: Manually deleting `*ModelSnapshot.cs`, source-control conflicts that dropped the snapshot, a misconfigured `options.UseXxx(...).MigrationsAssembly(typeof(...).Assembly.FullName)` pointing somewhere with no snapshot, or removing migrations until none remain and then removing once more.
Related errors
- Changes have been made to the model since the last migration
- You cannot add a migration with the name 'Migration'.
- The name '{migrationName}' is used by an existing migration.
- The migration '{name}' has already been applied to the datab
- No DbContext named '{name}' was found.
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/2d354998bf0a294f.
Report an issue: GitHub.