{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs#L17-L38","documentation":"MigrationsAssemblyExtensions.GetMigrationId asks the registered IMigrationsAssembly to resolve a migration by name or id and got null. EF needs the migration's full id (e.g. '20240101000000_Init') to know which file/class to instantiate. Used by the Migrator when a target migration name is supplied on the command line or via Migrate(target).","triggerScenarios":"Database.Migrate(\"WrongName\"), 'dotnet ef database update WrongName', or any code passing a migration name that does not match any registered migration id or suffix in the configured migrations assembly.","commonSituations":"Typo in the migration name; migration lives in a different assembly not configured via options.UseSqlServer(conn, sql => sql.MigrationsAssembly(typeof(...).Assembly.FullName)); migration was deleted/renamed but the script still references the old name; target name includes the timestamp prefix that does not match.","solutions":["Run 'dotnet ef migrations list' (or query db.Database.GetMigrations()) to see the exact available names and ids.","Pass the correct name (case-sensitive suffix or full timestamped id).","Verify options.MigrationsAssembly points at the assembly that actually contains the migration classes.","If the migration was removed, target a still-existing migration or '0' to revert all."],"exampleFix":"// before\nawait db.Database.MigrateAsync(\"Inital\"); // typo\n\n// after\nawait db.Database.MigrateAsync(\"Initial\");\n// or full id\nawait db.Database.MigrateAsync(\"20240101000000_Initial\");","handlingStrategy":"validation","validationCode":"// Verify a migration name resolves before passing it to Migrate\nstatic string ResolveMigration(DbContext db, string nameOrId)\n{\n    var assembly = db.GetService<IMigrationsAssembly>();\n    var id = assembly.FindMigrationId(nameOrId);\n    return id ?? throw new InvalidOperationException(\n        $\"Migration '{nameOrId}' not found. Available: \" +\n        string.Join(\", \", assembly.Migrations.Keys));\n}","typeGuard":"static bool MigrationExists(DbContext db, string name)\n    => db.GetService<IMigrationsAssembly>().FindMigrationId(name) is not null;","tryCatchPattern":null,"preventionTips":["List migrations first ('dotnet ef migrations list') before scripting a target name.","Validate the migrations assembly configuration in startup tests.","Prefer full timestamped ids when scripting rollback for clarity."],"tags":["migrations","lookup","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}