實體框架核心 - 更改“__EFMigrationsHistory”表的模式

entity-framework-core

是否可以在EntityFramework Core中更改__EFMigrationsHistory表的架構?

一般承認的答案

在您對UseSqlServer的調用中執行UseSqlServer

optionsBuilder
    .UseSqlServer(
        "...",
        x => x.MigrationsHistoryTable(
            HistoryRepository.DefaultTableName,
            "mySchema"));

熱門答案

查看源代碼( HistoryRepository.cs )。您可以在DbContext constructor配置自定義遷移表和模式名稱

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

或者在OnConfiguring method

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


Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因