{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L422-L458","documentation":"PrepareForMigration is the shared front door for any operation that scaffolds a migration (AddMigration path). It rejects a null, empty, or whitespace-only migration name before doing any work, because the name becomes both the class name and the file name. The check is string.IsNullOrWhiteSpace, so '   ' fails too.","triggerScenarios":"Calling any migration-scaffolding path that routes through PrepareForMigration with a name that is null, empty, or whitespace-only. Typically the CLI/PMC parse a missing positional/argument as null or empty string.","commonSituations":"Forgetting the migration name positional argument: 'dotnet ef migrations add' with no name; a script/CI step that interpolates an unset variable into the name; a GUI/tool that submits an empty string.","solutions":["Provide a non-empty migration name: 'dotnet ef migrations add InitialCreate'.","In scripted usage, validate the name variable is non-empty before invoking EF.","Avoid names that are only whitespace."],"exampleFix":"# before\ndotnet ef migrations add\n# after\ndotnet ef migrations add InitialCreate","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(migrationName))\n{\n    throw new ArgumentException(\"A migration name is required.\", nameof(migrationName));\n}","typeGuard":null,"tryCatchPattern":"try { operations.AddMigration(name, outputDir, contextType, ns, dryRun); }\ncatch (OperationException ex) when (ex.Message.Contains(\"migration name must be specified\"))\n{ /* supply a non-empty name */ }","preventionTips":["Always pass a positional migration name.","In scripts, assert the name variable is non-empty."],"tags":["migrations","argument-validation","cli"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}