{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs#L57-L93","documentation":"EF Core generates every migration as a class that derives from the `Migration` base class. Naming a migration \"Migration\" would produce a class literally called `Migration` deriving from `Migration` — a circular base-class dependency — so the scaffolder rejects the name up front (the resource key is `CircularBaseClassDependency`). The check is case-insensitive (`OrdinalIgnoreCase`), so \"migration\", \"MIGRATION\", etc. are all blocked.","triggerScenarios":"Running `dotnet ef migrations add Migration`, `Add-Migration Migration` (PMC), or programmatically calling `MigrationsScaffolder.ScaffoldMigration(\"Migration\", rootNamespace, subNamespace)` with any casing of the literal string \"migration\".","commonSituations":"Using a placeholder/generic name while experimenting, copy-pasting a command template whose name argument defaulted to the word \"migration\", or an automation script that passes a fixed string literal.","solutions":["Re-run the command with a descriptive, unique migration name (e.g. `InitialCreate`, `AddUserTable`).","If a script generates the name, ensure it never yields the literal \"migration\"."],"exampleFix":"// before\ndotnet ef migrations add Migration\n// after\ndotnet ef migrations add InitialCreate","handlingStrategy":"validation","validationCode":"// Validate migration name before scaffolding.\nstatic string ValidateMigrationName(string name)\n{\n    if (string.IsNullOrWhiteSpace(name))\n        throw new ArgumentException(\"Migration name is required.\", nameof(name));\n    if (string.Equals(name, \"migration\", StringComparison.OrdinalIgnoreCase))\n        throw new ArgumentException(\"A migration cannot be named 'Migration' (circular base class).\");\n    if (!System.Text.RegularExpressions.Regex.IsMatch(name, @\"^[A-Za-z_][A-Za-z0-9_]*$\"))\n        throw new ArgumentException(\"Migration name must be a valid C# identifier.\");\n    return name;\n}\n\n// usage\nvar name = ValidateMigrationName(args[0]);\nscaffolder.ScaffoldMigration(name, rootNamespace, subNamespace);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a descriptive, unique migration name to `dotnet ef migrations add`.","In automation, never use a fixed placeholder like \"migration\".","Validate the name as a C# identifier and reject the literal \"migration\" before calling ScaffoldMigration."],"tags":["ef-core","migrations","naming","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}