{"record":{"id":"d443fbbc0da0f367","repo":"dotnet/efcore","slug":"the-provider-provider-is-not-a-relational-prov","errorCode":null,"errorMessage":"The provider '{provider}' is not a Relational provider and therefore cannot be used with Migrations.","messagePattern":"The provider '(.+?)' is not a Relational provider and therefore cannot be used with Migrations\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/MigrationsOperations.cs","lineNumber":469,"sourceCode":"        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    {\n        var migrator = services.GetService<IMigrator>();\n        if (migrator == null)\n        {\n            var databaseProvider = services.GetService<IDatabaseProvider>();\n            throw new OperationException(DesignStrings.NonRelationalProvider(databaseProvider?.Name ?? \"Unknown\"));\n        }\n    }\n\n    private void EnsureMigrationsAssembly(IServiceProvider services)\n    {\n        var assemblyName = _assembly.GetName();\n        var options = services.GetRequiredService<IDbContextOptions>();\n        var contextType = services.GetRequiredService<ICurrentDbContext>().Context.GetType();\n        var optionsExtension = RelationalOptionsExtension.Extract(options);\n        if (optionsExtension.MigrationsAssemblyObject == null\n            || optionsExtension.MigrationsAssemblyObject != _assembly)\n        {\n            var migrationsAssemblyName = optionsExtension.MigrationsAssembly\n                ?? optionsExtension.MigrationsAssemblyObject?.GetName().Name\n                ?? contextType.Assembly.GetName().Name;\n            if (assemblyName.Name != migrationsAssemblyName\n                && assemblyName.FullName != migrationsAssemblyName)\n            {","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L451-L487","documentation":"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).","triggerScenarios":"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'.","commonSituations":"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.","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."],"exampleFix":"// before\noptions.UseInMemoryDatabase(\"Test\");\n// after (design-time / production)\noptions.UseSqlServer(connectionString);\n// (and keep InMemory only under an IntegrationTest config flag)","handlingStrategy":"validation","validationCode":"var provider = context.Database.ProviderName;\nif (!IsRelational(provider)) throw new InvalidOperationException($\"Provider '{provider}' is not relational and cannot use migrations.\");\nstatic bool IsRelational(string name) => name is not null && !name.EndsWith(\"InMemory\", StringComparison.Ordinal);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["efcore","migrations","provider","configuration"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}