{"record":{"id":"2d354998bf0a294f","repo":"dotnet/efcore","slug":"no-modelsnapshot-was-found","errorCode":null,"errorMessage":"No ModelSnapshot was found.","messagePattern":"No ModelSnapshot was found\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs","lineNumber":256,"sourceCode":"    /// <param name=\"force\">Revert the migration if it has been applied to the database.</param>\n    /// <param name=\"language\">The project's language.</param>\n    /// <param name=\"dryRun\">If <see langword=\"true\" />, then nothing is actually written to disk.</param>\n    /// <param name=\"offline\">Remove the migration without connecting to the database.</param>\n    /// <returns>The removed migration files.</returns>\n    public virtual MigrationFiles RemoveMigration(\n        string projectDir,\n        string? rootNamespace,\n        bool force,\n        string? language,\n        bool dryRun = false,\n        bool offline = false)\n    {\n        var files = new MigrationFiles();\n\n        var modelSnapshot = Dependencies.MigrationsAssembly.ModelSnapshot;\n        if (modelSnapshot == null)\n        {\n            throw new OperationException(DesignStrings.NoSnapshot);\n        }\n\n        var codeGenerator = Dependencies.MigrationsCodeGeneratorSelector.Select(language);\n\n        IModel? model = null;\n        var migrations = Dependencies.MigrationsAssembly.Migrations\n            .Select(m => Dependencies.MigrationsAssembly.CreateMigration(m.Value, _activeProvider))\n            .ToList();\n        if (migrations.Count != 0)\n        {\n            var migration = migrations[^1];\n            model = Dependencies.SnapshotModelProcessor.Process(migration.TargetModel);\n\n            if (!Dependencies.MigrationsModelDiffer.HasDifferences(\n                    model.GetRelationalModel(),\n                    Dependencies.SnapshotModelProcessor.Process(modelSnapshot.Model, resetVersion: true).GetRelationalModel()))\n            {\n                var applied = false;","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs#L238-L274","documentation":"`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.","triggerScenarios":"`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.","commonSituations":"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.","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."],"exampleFix":"// before\ndotnet ef migrations remove   // no ModelSnapshot present\n// after\ndotnet ef migrations add RestoreSnapshot   // regenerates ModelSnapshot\ndotnet ef migrations remove","handlingStrategy":"validation","validationCode":"// Ensure a ModelSnapshot exists before calling RemoveMigration.\nvar migrationsAssembly = serviceProvider\n    .GetRequiredService<Microsoft.EntityFrameworkCore.Migrations.IMigrationsAssembly>();\nif (migrationsAssembly.ModelSnapshot is null)\n    throw new InvalidOperationException(\n        \"No ModelSnapshot found. Re-add a migration to regenerate it before removing.\");\n\nscaffolder.RemoveMigration(projectDir, rootNamespace, force: false);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["ef-core","migrations","model-snapshot","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}