{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L60-L96","documentation":"AddMigration explicitly rejects the '*' wildcard because adding a migration requires a single concrete context (a migration is tied to one DbContext type). The '*' wildcard is only valid for read/loop commands that iterate all contexts (GetMigrations, ScriptMigration, UpdateDatabase).","triggerScenarios":"Running 'dotnet ef migrations add Init --context *'. The guard at line 76 (contextType == \"*\") throws before any context is created.","commonSituations":"Developer assumed '*' means 'use the only/default context'; copy-pasted a wildcard from a script-generation command into an add-migration call.","solutions":["Omit --context entirely (EF picks the single context if there is exactly one).","Pass the specific context name: --context MyDbContext.","If you genuinely need migrations for several contexts, run add-migration once per context."],"exampleFix":"// before\ndotnet ef migrations add Init --context *\n// after\ndotnet ef migrations add Init --context SalesDbContext","handlingStrategy":"validation","validationCode":"if (contextType == \"*\") throw new ArgumentException(\"AddMigration requires a specific context name; '*' is not allowed.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass '*' to add/remove migration commands.","Validate CLI args in wrapper scripts before invoking dotnet ef."],"tags":["efcore","migrations","cli","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}