{"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":446,"sourceCode":"        _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);\n\n        return services;\n    }\n\n    private static void EnsureServices(IServiceProvider services)\n    {","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L428-L464","documentation":"The migration name contains characters that are invalid in file names (Path.GetInvalidFileNameChars), because the name is used verbatim as the generated file's base name. PrepareForMigration rejects it before scaffolding so it never writes an unusable file.","triggerScenarios":"Any name containing a character in Path.GetInvalidFileNameChars() for the OS -- on Windows that includes < > : \\ / | ? * and control chars. e.g. 'Add(Order)' fails on '(' if the OS disallows it; most commonly '<', '>', ':', '\\', '/', '*', '?', '\"', '|'.","commonSituations":"Passing a sentence with punctuation; including slashes/path separators thinking they create subfolders; copy-pasting a name with parentheses or colons.","solutions":["Use a PascalCase identifier with no punctuation, e.g. 'AddOrderStatus'.","Strip or replace invalid characters before invoking the command.","Use --output-dir for folder placement instead of encoding paths in the name."],"exampleFix":"// before\ndotnet ef migrations add \"Add Order/Status\"\n// after\ndotnet ef migrations add AddOrderStatus --output-dir Migrations/Sales","handlingStrategy":"validation","validationCode":"var invalid = Path.GetInvalidFileNameChars();\nif (migrationName.Any(c => invalid.Contains(c))) throw new ArgumentException($\"Migration name contains invalid characters.\");","typeGuard":"static bool IsValidMigrationName(string n) => !n.Any(Path.GetInvalidFileNameChars().Contains);","tryCatchPattern":null,"preventionTips":["Stick to PascalCase identifiers for migration names.","Use --output-dir for folder structure, not the 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"}