ASP.NET Core multiple dbcontext cannot add migration

asp.net-core asp.net-core-2.0 c# ef-core-2.0 entity-framework-core

Question

I have 2 DbContexts:

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")));

when I try to run

dotnet ef migrations add Initial -c AppDbContext

I get:

No DbContext named 'AppDbContext' was found

If I run:

dotnet ef dbcontext list

the result is:

FullNamespace.ConfigDbContext

It doesn't seam to find the second DbContext AppDbContext

ConfigDbCOntext:

public class ConfigDbContext : DbContext
{
    public ConfigDbContext()
    {

    }

    public ConfigDbContext(DbContextOptions<ConfigDbContext> options) : base(options)
    {

    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
    }
}

AppDbContext:

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);
    }
}
1
2
10/12/2017 1:33:09 PM

Popular Answer

AppDbContext should be:

public class AppDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, Guid>
{
    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
    {

    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
    }
}
0
10/13/2017 3:20:00 AM


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