dotnet/efcore · error · OperationException
The wildcard '*' can only be used with commands that run for
Error message
The wildcard '*' can only be used with commands that run for all contexts found. Specify a context name for this command.
What it means
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).
Source
Thrown at src/EFCore.Design/Design/Internal/MigrationsOperations.cs:78
_servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, args);
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual MigrationFiles AddMigration(
string name,
string? outputDir,
string? contextType,
string? @namespace,
bool dryRun)
{
if (contextType == "*")
{
throw new OperationException(DesignStrings.WildcardNotSupported);
}
using var context = _contextOperations.CreateContext(contextType);
var services = PrepareForMigration(name, context);
using var scope = services.CreateScope();
var (_, files) =
CreateScaffoldedMigration(name, outputDir, @namespace, dryRun, scope.ServiceProvider);
return files;
}
/// <summary>
/// Creates and saves a scaffolded migration using the provided services.
/// </summary>
public virtual (ScaffoldedMigration Migration, MigrationFiles Files)
CreateScaffoldedMigration(
string name,
string? outputDir,View on GitHub (pinned to dbf9771522)
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.
Example fix
// before dotnet ef migrations add Init --context * // after dotnet ef migrations add Init --context SalesDbContext
Defensive patterns
Strategy: validation
Validate before calling
if (contextType == "*") throw new ArgumentException("AddMigration requires a specific context name; '*' is not allowed."); Prevention
- Never pass '*' to add/remove migration commands.
- Validate CLI args in wrapper scripts before invoking dotnet ef.
When it happens
Trigger: Running 'dotnet ef migrations add Init --context *'. The guard at line 76 (contextType == "*") throws before any context is created.
Common situations: Developer assumed '*' means 'use the only/default context'; copy-pasted a wildcard from a script-generation command into an add-migration call.
Related errors
- No DbContext named '{name}' was found.
- No DbContext was found in assembly '{assembly}'. Ensure that
- More than one DbContext named '{name}' was found. Specify wh
- More than one DbContext named '{name}' was found. Specify wh
- Changes have been made to the model since the last migration
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/791c0df6ead6b4e9.
Report an issue: GitHub.