Asp.Net EF Core error : More than one DbContext was found.

Dung Do Tien Jun 22 2021 1102

I have created a project with Asp.Net Core 3.1 and using EF core 2.0 with code first. I have created a DBContext as below:

 public class DBContext : IdentityDbContext<ApplicationUser>
    public DBContext(DbContextOptions<DBContext> options) : base(options) {}

    protected override void OnModelCreating(ModelBuilder modelBuilder)



 public void ConfigureServices(IServiceCollection services)
    services.AddDbContext<DBContext>(x => x.UseSqlServer(Configuration.GetConnectionString("SlaveConnection")));

And I try to run dotnet migration:

 dotnet ef migrations add CreateIdentity

But I got an error:

 More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands 

How can I resolve it?

Have 2 answer(s) found.
  • T

    Thủy Lê Jun 22 2021

    I usually use the command below to add a migration FE core in Core

     Add-Migration MyMigration --context DBContext

    I think your command has some mistake.

  • V

    Vuong Do Minh Jun 22 2021

    I think you are wrong about syntax. Please follow this syntax

     Add-Migration [-Name] <String> [-OutputDir <String>] [-Context <String>] [-Project <String>] [-StartupProject <String>] [-Environment <String>] [<CommonParameters>]

    you can try

     add-migration MyMigration -Context DBContext

    I hope it works for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close