I am using IdentityServer4 2.0.2, and have followed the QuickStart tutorial to use Entity Framework Core. I am trying to change from the default schema (dbo) to a custom schema in SQL Server. The following code is working correctly, instructing the DbContexts to look for the tables in the "idsrv4" schema.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var identityConnectionString = Configuration.GetConnectionString("Identity");
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddTestUsers(Config.GetUsers())
.AddConfigurationStore(options =>
{
options.DefaultSchema = "idsrv4";
options.ConfigureDbContext = builder => builder.UseSqlServer(identityConnectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
})
.AddOperationalStore(options =>
{
options.DefaultSchema = "idsrv4";
options.ConfigureDbContext = builder => builder.UseSqlServer(identityConnectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
});
}
In my development environment, I am initializing the database from the Configure() method in Startup.cs with the following code:
var context = serviceScope.ServiceProvider.GetRequiredService<ConfigurationDbContext>();
context.Database.Migrate();
The problem is that the tables are still being created in the dbo schema. How can I instruct the Migrate() method (from Microsoft.EntityFrameworkCore) to use the schema that I've provided?