dotnet/efcore · error · OperationException
The provider '{provider}' is not a Relational provider and t
Error message
The provider '{provider}' is not a Relational provider and therefore cannot be used with Migrations. What it means
EnsureServices failed to resolve an IMigrator from the design-time service provider, meaning the active database provider is not a Relational provider. Migrations are a relational concept (they produce SQL); in-memory and other non-relational providers do not register a migrator. The thrown message names the provider (or 'Unknown' if IDatabaseProvider itself was absent).
Source
Thrown at src/EFCore.Design/Design/Internal/MigrationsOperations.cs:469
if (string.Equals(name, contextClassName, StringComparison.Ordinal))
{
throw new OperationException(
DesignStrings.ConflictingContextAndMigrationName(name));
}
var services = _servicesBuilder.Build(context);
EnsureServices(services);
return services;
}
private static void EnsureServices(IServiceProvider services)
{
var migrator = services.GetService<IMigrator>();
if (migrator == null)
{
var databaseProvider = services.GetService<IDatabaseProvider>();
throw new OperationException(DesignStrings.NonRelationalProvider(databaseProvider?.Name ?? "Unknown"));
}
}
private void EnsureMigrationsAssembly(IServiceProvider services)
{
var assemblyName = _assembly.GetName();
var options = services.GetRequiredService<IDbContextOptions>();
var contextType = services.GetRequiredService<ICurrentDbContext>().Context.GetType();
var optionsExtension = RelationalOptionsExtension.Extract(options);
if (optionsExtension.MigrationsAssemblyObject == null
|| optionsExtension.MigrationsAssemblyObject != _assembly)
{
var migrationsAssemblyName = optionsExtension.MigrationsAssembly
?? optionsExtension.MigrationsAssemblyObject?.GetName().Name
?? contextType.Assembly.GetName().Name;
if (assemblyName.Name != migrationsAssemblyName
&& assemblyName.FullName != migrationsAssemblyName)
{View on GitHub (pinned to dbf9771522)
Solutions
- Switch OnConfiguring to a relational provider (UseSqlServer/UseNpgsql/UseSqlite/etc.) for the environment where you run migrations.
- If you need InMemory for tests, gate provider selection by configuration so design-time uses a relational provider.
- For a custom provider, derive from the relational infrastructure and register IMigrator.
Example fix
// before
options.UseInMemoryDatabase("Test");
// after (design-time / production)
options.UseSqlServer(connectionString);
// (and keep InMemory only under an IntegrationTest config flag) Defensive patterns
Strategy: validation
Validate before calling
var provider = context.Database.ProviderName;
if (!IsRelational(provider)) throw new InvalidOperationException($"Provider '{provider}' is not relational and cannot use migrations.");
static bool IsRelational(string name) => name is not null && !name.EndsWith("InMemory", StringComparison.Ordinal); Prevention
- Reserve InMemory for tests; gate it behind an env flag.
- Configure a relational provider in the design-time environment.
- Assert provider is relational before invoking migrations in code.
When it happens
Trigger: DbContext.OnConfiguring uses UseInMemoryDatabase (or a custom non-relational provider) and you run any migrations command. services.GetService<IMigrator>() at line 465 returns null, databaseProvider is e.g. 'Microsoft.EntityFrameworkCore.InMemory'.
Common situations: Dev/test setup uses the InMemory provider and someone runs 'dotnet ef migrations add'; a provider selection bug returns the InMemory provider in production config; custom provider that doesn't implement the relational stack.
Related errors
- Unable to find expected assembly attribute [DesignTimeProvid
- Your target project '{assembly}' doesn't match your migratio
- The current migration SQL generator '{sqlGeneratorType}' is
- Unable to find a store type mapping for column '{table}.{col
- Cosmos-specific methods can only be used when the context is
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/d443fbbc0da0f367.
Report an issue: GitHub.