简体   繁体   中英

ASP.NET Core Web API Error - How to resolve More than one DbContext was found. Specify which one to use in update-database

In ASP.NET Core-6 Web API, I have two DBContexts:

  1. ApplicationIdentityDbContext
  2. MyAppDbContext

For add-migration, I used these two in the PM :

  1. add-migration InitialIdentity -OutputDir "Infrastructure/Identity/Migrations" -context ApplicationIdentityDbContext
  2. add-migration InitialDDM -OutputDir "Persistence/Migrations" -context MyAppDbContext

The two add-migration works.

However, for the update-database when I did:

update-database -verbose

I got this error:

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

How do I resolve this?

Thank you

If you are using Visual Studio's Package Manager Console with reference to Microsoft.EntityFrameworkCore.Tools , then you can execute the following command:

PM> Update-Database -context your_context -v 

If you use do.net command, then try this:

dotnet ef database update --context your_context

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM