{"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":453,"sourceCode":"    /// </summary>\n    public virtual IServiceProvider PrepareForMigration(string name, DbContext context)\n    {\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    }","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L435-L471","documentation":"The chosen migration name equals the DbContext class name, which would collide with the generated migration class (EF derives a class named <MigrationName> from the name). PrepareForMigration compares name to context.GetType().Name with Ordinal and rejects the match, suggesting 'InitialCreate' for the first migration.","triggerScenarios":"Running 'dotnet ef migrations add <ContextName>' where <ContextName> is literally the DbContext subclass name (e.g. context is SalesDbContext and you pass 'SalesDbContext').","commonSituations":"Developer names the first migration after the context out of habit; templating scripts that interpolate the context name into the migration name.","solutions":["Pick a different name describing the change, e.g. 'Init' or 'InitialCreate' for the first migration.","If scripting, append a suffix like '_Initial' to the context name.","Follow the convention of verb-noun migration names (AddX, RemoveY)."],"exampleFix":"// before: context class is SalesDbContext\ndotnet ef migrations add SalesDbContext\n// after\ndotnet ef migrations add InitialCreate","handlingStrategy":"validation","validationCode":"if (string.Equals(migrationName, context.GetType().Name, StringComparison.Ordinal)) throw new ArgumentException(\"Migration name must differ from the context class name.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 'InitialCreate' for the first migration by convention.","Never interpolate the context name into the migration name."],"tags":["efcore","migrations","cli","validation","naming"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}