{"record":{"id":"2fba6a839052251c","repo":"dotnet/efcore","slug":"the-name-you-have-chosen-for-the-migration-name","errorCode":null,"errorMessage":"The name you have chosen for the migration, '{name}', is the same as the context class name. Please choose a different name for your migration. Might we suggest 'InitialCreate' for your first migration?","messagePattern":"The name you have chosen for the migration, '(.+?)', is the same as the context class name\\. Please choose a different name for your migration\\. Might we suggest 'InitialCreate' for your first migration\\?","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/MigrationsOperations.cs","lineNumber":455,"sourceCode":"    {\n        if (string.IsNullOrWhiteSpace(name))\n        {\n            throw new OperationException(DesignStrings.MigrationNameRequired);\n        }\n\n        var invalidPathChars = Path.GetInvalidFileNameChars();\n        if (name.Any(c => invalidPathChars.Contains(c)))\n        {\n            throw new OperationException(\n                DesignStrings.BadMigrationName(name, string.Join(\"','\", invalidPathChars)));\n        }\n\n        var contextClassName = context.GetType().Name;\n        if (string.Equals(name, contextClassName, StringComparison.Ordinal))\n        {\n            throw new OperationException(\n                DesignStrings.ConflictingContextAndMigrationName(name));\n        }\n\n        var services = _servicesBuilder.Build(context);\n        EnsureServices(services);\n\n        return services;\n    }\n\n    private static void EnsureServices(IServiceProvider services)\n    {\n        var migrator = services.GetService<IMigrator>();\n        if (migrator == null)\n        {\n            var databaseProvider = services.GetService<IDatabaseProvider>();\n            throw new OperationException(DesignStrings.NonRelationalProvider(databaseProvider?.Name ?? \"Unknown\"));\n        }\n    }\n\n    private void EnsureMigrationsAssembly(IServiceProvider services)","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L437-L473","documentation":"PrepareForMigration forbids a migration whose name equals the DbContext class's simple type name (ordinal, case-sensitive compare). EF generates a migration class derived from Migration named '<MigrationName>'; if that collides with the context class name the generated code would shadow/conflict with the context type, and the scaffolded namespace would be ambiguous. The message suggests 'InitialCreate' as a safe default.","triggerScenarios":"Calling PrepareForMigration where name exactly equals context.GetType().Name (case-sensitive). For a context 'ShopDbContext', passing 'ShopDbContext' trips the guard.","commonSituations":"User names the first migration after the context by reflex; tooling auto-suggests the context name; the context was renamed and an old migration name now matches the new context name.","solutions":["Choose a migration name different from your DbContext class name (e.g. 'InitialCreate', 'AddProducts').","Rename the DbContext if the migration name is intentional and the context name is the one you'd rather change."],"exampleFix":"// DbContext: ShopDbContext\n# before\ndotnet ef migrations add ShopDbContext\n# after\ndotnet ef migrations add InitialCreate","handlingStrategy":"validation","validationCode":"if (string.Equals(name, context.GetType().Name, StringComparison.Ordinal))\n{\n    throw new ArgumentException(\"Migration name must differ from the DbContext class name.\");\n}","typeGuard":null,"tryCatchPattern":"try { operations.AddMigration(name, ...); }\ncatch (OperationException ex) when (ex.Message.Contains(\"same as the context class name\"))\n{ /* choose a different name like InitialCreate */ }","preventionTips":["Never name a migration after the context.","Use a domain verb+noun convention."],"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"}