{"record":{"id":"ca44009556517e11","repo":"dotnet/efcore","slug":"a-migration-name-must-be-specified","errorCode":null,"errorMessage":"A migration name must be specified.","messagePattern":"A migration name must be specified\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/MigrationsOperations.cs","lineNumber":440,"sourceCode":"        var migrationsAssembly = scope.ServiceProvider.GetRequiredService<IMigrationsAssembly>();\n        var compiledAssembly = compiler.CompileMigration(migration, context.GetType());\n        migrationsAssembly.AddMigrations(compiledAssembly);\n\n        migrator.Migrate(migration.MigrationId);\n\n        _reporter.WriteInformation(DesignStrings.MigrationCreatedAndApplied(migration.MigrationId));\n\n        return files;\n    }\n\n    /// <summary>\n    ///     Prepares common resources for migration operations.\n    /// </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);","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L422-L458","documentation":"AddMigration / AddAndApplyMigration -> PrepareForMigration requires a non-empty migration name (line 438). The name becomes a file name and a class name, so an empty or whitespace string is rejected up front.","triggerScenarios":"Calling dotnet ef migrations add with no argument, or AddMigration(name: \"\") / AddMigration(name: null) via the API. string.IsNullOrWhiteSpace(name) is true.","commonSituations":"Scripting the CLI and forgetting to interpolate the name; invoking the API programmatically with a computed name that came back empty; tooling that prompts for a name and got an empty response.","solutions":["Supply a meaningful PascalCase name, e.g. 'AddOrderStatus'.","Validate/guard the name variable in your script before invoking the command.","If calling the API, default to a generated name derived from the change."],"exampleFix":"// before\ndotnet ef migrations add \"\"\n// after\ndotnet ef migrations add AddOrderStatus","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(migrationName)) throw new ArgumentException(\"A migration name is required.\");","typeGuard":"static bool IsValidMigrationName(string? n) => !string.IsNullOrWhiteSpace(n);","tryCatchPattern":null,"preventionTips":["Default to a generated name when none is supplied.","Validate CLI args in wrapper scripts."],"tags":["efcore","migrations","cli","validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}