dotnet/efcore · error · OperationException
You cannot add a migration with the name 'Migration'.
Error message
You cannot add a migration with the name 'Migration'.
What it means
MigrationsScaffolder.ScaffoldMigration forbids a migration literally named 'Migration' (case-insensitive) because the generated migration class derives from the base 'Migration' class; naming it 'Migration' would create a circular base-class dependency (class Migration : global::Microsoft.EntityFrameworkCore.Migrations.Migration is illegal). The guard is a simple string.Equals against 'migration' with OrdinalIgnoreCase.
Solutions
- Pick any other name, e.g. 'InitialCreate', 'AddOrders', 'v1'.
Example fix
# before dotnet ef migrations add migration # after dotnet ef migrations add InitialCreate
Defensive patterns
Strategy: validation
Validate before calling
if (string.Equals(migrationName, "migration", StringComparison.OrdinalIgnoreCase))
{
throw new ArgumentException("Migration name cannot be 'Migration'.", nameof(migrationName));
} Try / catch
try { scaffolder.ScaffoldMigration(name, rootNs, subNs, language, dryRun); }
catch (OperationException ex) when (ex.Message.Contains("with the name 'Migration'"))
{ /* pick a different name */ } Prevention
- Avoid using the noun 'Migration' as a migration name.
- Use domain-driven names.
When it happens
Trigger: Calling ScaffoldMigration with migrationName == "Migration" (any case). The check fires before duplicate-name and namespace handling.
Common situations: User types 'dotnet ef migrations add migration'; a tool/scaffold defaults the name to the noun 'Migration'; copy-paste of a generic template.
Related errors
- The name you have chosen for the migration
- The project language
- A migration name must be specified.
- A seed entity for entity type
- A seed entity for entity type
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/5fb65d4c7a4cfe08.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs:75
/// namespace generation, just use sub-namespace as is.
/// </param>
/// <param name="subNamespace">
/// The migration's sub-namespace. Note: the root-namespace and
/// the sub-namespace should not both be empty.
/// </param>
/// <param name="language">The project's language.</param>
/// <param name="dryRun">If <see langword="true" />, then nothing is actually written to disk.</param>
/// <returns>The scaffolded migration.</returns>
public virtual ScaffoldedMigration ScaffoldMigration(
string migrationName,
string? rootNamespace,
string? subNamespace = null,
string? language = null,
bool dryRun = false)
{
if (string.Equals(migrationName, "migration", StringComparison.OrdinalIgnoreCase))
{
throw new OperationException(DesignStrings.CircularBaseClassDependency);
}
if (Dependencies.MigrationsAssembly.FindMigrationId(migrationName) != null)
{
throw new OperationException(DesignStrings.DuplicateMigrationName(migrationName));
}
var overrideNamespace = rootNamespace == null;
var subNamespaceDefaulted = false;
if (string.IsNullOrEmpty(subNamespace) && !overrideNamespace)
{
subNamespaceDefaulted = true;
subNamespace = "Migrations";
}
var (key, typeInfo) = Dependencies.MigrationsAssembly.Migrations.LastOrDefault();
var migrationNamespace =View on GitHub (pinned to 3a2006ef56)