是否可以在EntityFramework Core中更改__EFMigrationsHistory
表的架构?
答案 0 :(得分:18)
在致电UseSqlServer
时这样做。
optionsBuilder
.UseSqlServer(
"...",
x => x.MigrationsHistoryTable(
HistoryRepository.DefaultTableName,
"mySchema"));
答案 1 :(得分:7)
查看源代码(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";
}