{"record":{"id":"0492abe68a8d4e5a","repo":"dotnet/efcore","slug":"the-migration-migrationname-was-not-found","errorCode":null,"errorMessage":"The migration '{migrationName}' was not found.","messagePattern":"The migration '(.+?)' was not found\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs","lineNumber":35,"sourceCode":"    /// </summary>\n    /// <remarks>\n    ///     <para>\n    ///         An exception is thrown if the migration was not found--use\n    ///         <see cref=\"IMigrationsAssembly.FindMigrationId\" /> if the migration may not exist.\n    ///     </para>\n    ///     <para>\n    ///         See <see href=\"https://aka.ms/efcore-docs-migrations\">Database migrations</see> for more information and examples.\n    ///     </para>\n    /// </remarks>\n    /// <param name=\"assembly\">The assembly.</param>\n    /// <param name=\"nameOrId\">The name or identifier to lookup.</param>\n    /// <returns>The identifier of the migration.</returns>\n    public static string GetMigrationId(this IMigrationsAssembly assembly, string nameOrId)\n    {\n        Check.NotEmpty(nameOrId);\n\n        var id = assembly.FindMigrationId(nameOrId);\n        return id ?? throw new InvalidOperationException(RelationalStrings.MigrationNotFound(nameOrId));\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs#L17-L38","documentation":"Thrown by MigrationsAssemblyExtensions.GetMigrationId when `IMigrationsAssembly.FindMigrationId` returns null for the requested name or id. EF could not locate a registered migration matching the supplied string, so a lookup that requires the migration to exist fails.","triggerScenarios":"Calling `Database.Migrate(\"SomeName\")` or `dotnet ef database update SomeName` with a migration name/id that does not exist in the configured migrations assembly; typos; migration not yet added; wrong assembly configured.","commonSituations":"Typo in the migration name; calling `Migrate` with a name from a different DbContext/assembly; migrations registered in a separate assembly not passed to `MigrationsAssembly`; deleted/renamed migrations.","solutions":["List available migrations (`dotnet ef migrations list`) and use an exact name/id.","Ensure the migrations assembly is configured: `.MigrationsAssembly(\"MyProject.Migrations\")`.","Add the missing migration via `dotnet ef migrations add <Name>` if it does not exist yet.","Check for typos and trailing/leading spaces in the supplied name."],"exampleFix":"// before\ndb.Database.Migrate(\"AddFos\"); // typo\n// after\ndb.Database.Migrate(\"AddFoos\");","handlingStrategy":"type-guard","validationCode":"// Use the non-throwing lookup before calling Migrate with a target name.\nvar id = db.GetService<IMigrationsAssembly>().FindMigrationId(name);\nif (id is null)\n    throw new InvalidOperationException($\"Migration '{name}' not found. Available: \"\n        + string.Join(\", \", db.GetService<IMigrationsAssembly>().Migrations.Keys));\ndb.Database.Migrate(id);","typeGuard":"bool MigrationExists(IMigrationsAssembly asm, string nameOrId)\n    => asm.FindMigrationId(nameOrId) is not null;","tryCatchPattern":null,"preventionTips":["Use `FindMigrationId` (returns null) instead of `GetMigrationId` (throws) when the migration may not exist.","List migrations with `dotnet ef migrations list` before scripting updates.","Configure the correct `.MigrationsAssembly(...)` so names resolve."],"tags":["efcore","migrations","lookup","relational"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}