{"record":{"id":"5fb65d4c7a4cfe08","repo":"dotnet/efcore","slug":"you-cannot-add-a-migration-with-the-name-migratio","errorCode":null,"errorMessage":"You cannot add a migration with the name 'Migration'.","messagePattern":"You cannot add a migration with the name 'Migration'\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs","lineNumber":75,"sourceCode":"    ///     namespace generation, just use sub-namespace as is.\n    /// </param>\n    /// <param name=\"subNamespace\">\n    ///     The migration's sub-namespace. Note: the root-namespace and\n    ///     the sub-namespace should not both be empty.\n    /// </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    /// <returns>The scaffolded migration.</returns>\n    public virtual ScaffoldedMigration ScaffoldMigration(\n        string migrationName,\n        string? rootNamespace,\n        string? subNamespace = null,\n        string? language = null,\n        bool dryRun = false)\n    {\n        if (string.Equals(migrationName, \"migration\", StringComparison.OrdinalIgnoreCase))\n        {\n            throw new OperationException(DesignStrings.CircularBaseClassDependency);\n        }\n\n        if (Dependencies.MigrationsAssembly.FindMigrationId(migrationName) != null)\n        {\n            throw new OperationException(DesignStrings.DuplicateMigrationName(migrationName));\n        }\n\n        var overrideNamespace = rootNamespace == null;\n        var subNamespaceDefaulted = false;\n        if (string.IsNullOrEmpty(subNamespace) && !overrideNamespace)\n        {\n            subNamespaceDefaulted = true;\n            subNamespace = \"Migrations\";\n        }\n\n        var (key, typeInfo) = Dependencies.MigrationsAssembly.Migrations.LastOrDefault();\n\n        var migrationNamespace =","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs#L57-L93","documentation":"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.","triggerScenarios":"Calling ScaffoldMigration with migrationName == \"Migration\" (any case). The check fires before duplicate-name and namespace handling.","commonSituations":"User types 'dotnet ef migrations add migration'; a tool/scaffold defaults the name to the noun 'Migration'; copy-paste of a generic template.","solutions":["Pick any other name, e.g. 'InitialCreate', 'AddOrders', 'v1'."],"exampleFix":"# before\ndotnet ef migrations add migration\n# after\ndotnet ef migrations add InitialCreate","handlingStrategy":"validation","validationCode":"if (string.Equals(migrationName, \"migration\", StringComparison.OrdinalIgnoreCase))\n{\n    throw new ArgumentException(\"Migration name cannot be 'Migration'.\", nameof(migrationName));\n}","typeGuard":null,"tryCatchPattern":"try { scaffolder.ScaffoldMigration(name, rootNs, subNs, language, dryRun); }\ncatch (OperationException ex) when (ex.Message.Contains(\"with the name 'Migration'\"))\n{ /* pick a different name */ }","preventionTips":["Avoid using the noun 'Migration' as a migration name.","Use domain-driven names."],"tags":["migrations","naming","code-generation","conflict"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}