{"record":{"id":"1c6b059e38b2d9e9","repo":"dotnet/efcore","slug":"the-migration-name-name-is-not-valid-migratio","errorCode":null,"errorMessage":"The migration name '{name}' is not valid. Migration names cannot contain any of the following characters: '{characters}'.","messagePattern":"The migration name '(.+?)' is not valid\\. Migration names cannot contain any of the following characters: '(.+?)'\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/MigrationsOperations.cs","lineNumber":448,"sourceCode":"        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);\n\n        return services;\n    }\n\n    private static void EnsureServices(IServiceProvider services)\n    {\n        var migrator = services.GetService<IMigrator>();\n        if (migrator == null)","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L430-L466","documentation":"PrepareForMigration checks the migration name against Path.GetInvalidFileNameChars() because the name is used as a file name (the migration id is '<Name>_<Timestamp>'). Any invalid character (e.g. ':', '\\\\', '/', '*', '?', '\"', '<', '>', '|') is rejected and listed in the message so the user knows exactly which characters to remove.","triggerScenarios":"Calling PrepareForMigration with a name containing any OS-invalid filename character. Cross-platform tooling uses the union of invalid chars; on Windows this includes the classic reserved set.","commonSituations":"Naming a migration with a date containing slashes ('2024/01/Init'), with a namespace dot-path style that includes '\\\\', or with punctuation like 'Add:Orders'; copy-pasting a name with trailing/leading spaces or quotes.","solutions":["Use an alphanumeric, PascalCase name with no path separators or reserved punctuation (e.g. 'AddOrderTable').","Strip any of: <>:\"/\\\\|?* and control characters from the proposed name before running the command.","If you wanted namespacing, use the --namespace flag instead of embedding separators in the name."],"exampleFix":"# before\ndotnet ef migrations add Add:Order\n# after\ndotnet ef migrations add AddOrder","handlingStrategy":"validation","validationCode":"var invalid = Path.GetInvalidFileNameChars();\nif (name.Any(c => invalid.Contains(c)))\n{\n    throw new ArgumentException($\"Migration name contains invalid characters: {string.Join(\", \", name.Where(c => invalid.Contains(c)))}\");\n}","typeGuard":null,"tryCatchPattern":"try { operations.AddMigration(name, ...); }\ncatch (OperationException ex) when (ex.Message.Contains(\"is not valid. Migration names cannot contain\"))\n{ /* sanitize the name and retry */ }","preventionTips":["Use PascalCase alphanumeric names.","Avoid date separators with slashes; use underscores.","Validate names in scripted usage."],"tags":["migrations","argument-validation","filesystem","cli"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}