{"record":{"id":"791c0df6ead6b4e9","repo":"dotnet/efcore","slug":"the-wildcard-can-only-be-used-with-commands-th-791c0d","errorCode":null,"errorMessage":"The wildcard '*' can only be used with commands that run for all contexts found. Specify a context name for this command.","messagePattern":"The wildcard '\\*' can only be used with commands that run for all contexts found\\. Specify a context name for this command\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/MigrationsOperations.cs","lineNumber":78,"sourceCode":"        _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, args);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual MigrationFiles AddMigration(\n        string name,\n        string? outputDir,\n        string? contextType,\n        string? @namespace,\n        bool dryRun)\n    {\n        if (contextType == \"*\")\n        {\n            throw new OperationException(DesignStrings.WildcardNotSupported);\n        }\n\n        using var context = _contextOperations.CreateContext(contextType);\n        var services = PrepareForMigration(name, context);\n\n        using var scope = services.CreateScope();\n        var (_, files) =\n            CreateScaffoldedMigration(name, outputDir, @namespace, dryRun, scope.ServiceProvider);\n        return files;\n    }\n\n    /// <summary>\n    ///     Creates and saves a scaffolded migration using the provided services.\n    /// </summary>\n    public virtual (ScaffoldedMigration Migration, MigrationFiles Files)\n        CreateScaffoldedMigration(\n            string name,\n            string? outputDir,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L60-L96","documentation":"AddMigration rejects the literal context name '*' because adding a migration targets exactly one DbContext and must write files into one migrations assembly; the '*' wildcard (meaning 'all contexts') is only valid for commands that fan out across every context. The guard fires before any context is even created, so the throw is purely argument validation.","triggerScenarios":"Invoking MigrationsOperations.AddMigration with contextType == \"*\". This typically happens when a caller (a CLI wrapper, scripting tool, or test) passes the wildcard where a single context name is expected. The built-in dotnet ef / PMC commands never pass '*' to AddMigration.","commonSituations":"A custom tooling wrapper or PowerShell script that mechanically forwards a '--context *' flag to every EF command; misunderstanding which verbs accept the wildcard (Drop/Update/Script/List-Migration do; Add/Remove do not).","solutions":["Pass a concrete context name (or omit --context to let EF pick the only/Default) instead of '*'.","If you genuinely need migrations for several contexts, invoke AddMigration once per context name in a loop."],"exampleFix":"// before\ndotnet ef migrations add Initial --context *\n// after\ndotnet ef migrations add Initial --context MyDbContext","handlingStrategy":"validation","validationCode":"// In a CLI wrapper, only pass '*' to verbs that accept it\nstatic readonly HashSet<string> WildcardOk = new() { \"database update\", \"migrations list\", \"migrations script\" };\nif (contextArg == \"*\" && !WildcardOk.Contains(verb))\n{\n    throw new ArgumentException(\"'--context *' is not valid for this verb. Specify a context name.\");\n}","typeGuard":null,"tryCatchPattern":"try { operations.AddMigration(name, outputDir, contextType, ns, dryRun); }\ncatch (OperationException ex) when (ex.Message.Contains(\"wildcard '*' can only be used\"))\n{ /* re-run with an explicit context name */ }","preventionTips":["Treat '*' as opt-in per verb, not a generic flag.","Validate tooling inputs before forwarding to EF.","Document which EF verbs accept the wildcard."],"tags":["migrations","argument-validation","cli","wildcard"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}