{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L451-L487","documentation":"EnsureServices verifies that a relational IMigrator is registered in the design-time service provider. If only a non-relational provider is active (e.g. the in-memory provider), IDatabaseProvider is non-relational and there is no IMigrator, so migrations cannot be generated or applied. The message reports the provider's Name (or 'Unknown' if IDatabaseProvider itself is absent).","triggerScenarios":"Calling any migration operation that runs EnsureServices (the migrations path of AddMigration/RemoveMigration/etc.) when the configured database provider is not relational. Examples: UseInMemoryDatabase, or a provider whose Name does not indicate relational support, leaving services.GetService<IMigrator>() null.","commonSituations":"Running 'dotnet ef migrations add' against a DbContext configured with UseInMemoryDatabase() (often used in tests); a test/seed context accidentally selected as the design-time context; misconfigured OnConfiguring pointing at a non-relational provider.","solutions":["Configure a relational provider in your DbContext (UseSqlServer, UseNpgsql, UseSqlite, UseMySql, etc.) at design time.","Ensure the design-time context (the one EF tools instantiate) is the production/relational one, not a test context using InMemory.","If you have multiple contexts, pass the correct --context that uses a relational provider."],"exampleFix":"// before\noptionsBuilder.UseInMemoryDatabase(\"tests\");\n// after\noptionsBuilder.UseSqlServer(connectionString);","handlingStrategy":"validation","validationCode":"var provider = dbContextOptions.Extensions.OfType<CoreOptionsExtension>().FirstOrDefault();\nvar isRelational = dbContextOptions.Extensions.OfType<RelationalOptionsExtension>().Any();\nif (!isRelational)\n{\n    throw new InvalidOperationException(\"A relational provider is required for migrations.\");\n}","typeGuard":null,"tryCatchPattern":"try { operations.AddMigration(...); }\ncatch (OperationException ex) when (ex.Message.Contains(\"not a Relational provider\"))\n{ /* switch from InMemory to SqlServer/Sqlite/etc. */ }","preventionTips":["Don't use UseInMemoryDatabase for the context EF tools target.","Keep a dedicated relational design-time context if tests use InMemory."],"tags":["migrations","provider","relational","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}