Entity Framework Core - change schema of "__EFMigrationsHistory" table

entity-framework-core

Question

Is it possible to change schema of __EFMigrationsHistory table in EntityFramework Core?

1
11
7/27/2017 8:12:40 AM

Accepted Answer

Do it in your call to UseSqlServer.

optionsBuilder
    .UseSqlServer(
        "...",
        x => x.MigrationsHistoryTable(
            HistoryRepository.DefaultTableName,
            "mySchema"));
27
8/9/2016 6:34:49 PM

Popular Answer

Looking into source code (HistoryRepository.cs). You can configure custom migrations table and schema names, inside DbContext constructor

public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
    var relationalOptions = RelationalOptionsExtension.Extract(options);
    relationalOptions.MigrationsHistoryTableName = "bar";
    relationalOptions.MigrationsHistoryTableSchema = "foo";
}

or inside OnConfiguring method

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    var relationalOptions = RelationalOptionsExtension.Extract(optionsBuilder.Options);
    relationalOptions.MigrationsHistoryTableName = "bar";
    relationalOptions.MigrationsHistoryTableSchema = "foo";
}


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow