dotnet/efcore · error · InvalidOperationException
The migration '{migrationName}' was not found.
Error message
The migration '{migrationName}' was not found. What it means
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.
Source
Thrown at src/EFCore.Relational/Migrations/MigrationsAssemblyExtensions.cs:35
/// </summary>
/// <remarks>
/// <para>
/// An exception is thrown if the migration was not found--use
/// <see cref="IMigrationsAssembly.FindMigrationId" /> if the migration may not exist.
/// </para>
/// <para>
/// See <see href="https://aka.ms/efcore-docs-migrations">Database migrations</see> for more information and examples.
/// </para>
/// </remarks>
/// <param name="assembly">The assembly.</param>
/// <param name="nameOrId">The name or identifier to lookup.</param>
/// <returns>The identifier of the migration.</returns>
public static string GetMigrationId(this IMigrationsAssembly assembly, string nameOrId)
{
Check.NotEmpty(nameOrId);
var id = assembly.FindMigrationId(nameOrId);
return id ?? throw new InvalidOperationException(RelationalStrings.MigrationNotFound(nameOrId));
}
}
View on GitHub (pinned to dbf9771522)
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.
Example fix
// before
db.Database.Migrate("AddFos"); // typo
// after
db.Database.Migrate("AddFoos"); Defensive patterns
Strategy: type-guard
Validate before calling
// Use the non-throwing lookup before calling Migrate with a target name.
var id = db.GetService<IMigrationsAssembly>().FindMigrationId(name);
if (id is null)
throw new InvalidOperationException($"Migration '{name}' not found. Available: "
+ string.Join(", ", db.GetService<IMigrationsAssembly>().Migrations.Keys));
db.Database.Migrate(id); Type guard
bool MigrationExists(IMigrationsAssembly asm, string nameOrId)
=> asm.FindMigrationId(nameOrId) is not null; Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- User transaction is not supported with a TransactionSuppress
- The default value has not been specified for the column '{ta
- The default value SQL has not been specified for the column
- The computed column SQL has not been specified for the colum
- A seed entity for entity type '{entityType}' has the same ke
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/0492abe68a8d4e5a.
Report an issue: GitHub.