我有 2 个 DbContext:
services.AddDbContext<ConfigDbContext>(options => options.UseSqlServer(Configuration["Data:ConfigSQLServer:ConnectionString"].ToString(), t => t.MigrationsAssembly("App.Web")));
services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration["Data:AppSQLServer:ConnectionString"].ToString(), t => t.MigrationsAssembly("App.Web")));
当我尝试跑步时
dotnet ef migrations add Initial -c AppDbContext
我得到:
No DbContext named 'AppDbContext' was found
如果我运行:
dotnet ef dbcontext list
结果是:
FullNamespace.ConfigDbContext
找不到第二个 DbContextAppDbContext
配置数据库上下文:
public class ConfigDbContext : DbContext
{
public ConfigDbContext()
{
}
public ConfigDbContext(DbContextOptions<ConfigDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
应用数据库上下文:
public class AppDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, Guid>
{
public AppDbContext()
{
}
public ConfigDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}