Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core EF Add-Migration command not working

Following this Microsoft Tutorial when I run the PM> Add-Migration MyFirstMigration command in VS2015 project created from the same tutorial I get the following error that I can't resolve:

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.

Point to note

  1. I'm using the above tutorial with the exception that I'm using Individual User Account authentication instead of No Authentication used in the tutorial.
  2. I've latest release of ASP.NeT Core 1.0 and VS2015-Update 3 on windows 8.1
  3. This is a freshly created project. No other DbContext was manually installed
like image 736
nam Avatar asked Jul 02 '16 16:07

nam


People also ask

Why add migration is not working?

Add-Migration - The Term 'Add-Migration' Is Not Recognized After creating models and context class, we nomally add migration to initialize the database. The error occurs sometimes while adding migration in asp.net core, entity framework with code first approach because of some missing library.

How do I add migration to EF core?

Adding a Migration So, firstly, you need to create a migration. Open the Package Manager Console from the menu Tools -> NuGet Package Manager -> Package Manager Console in Visual Studio and execute the following command to add a migration.

How do you Unapply a migration in asp net core with EF core?

Delete the row corresponding to your migration that you want to unapply (Say "yes" to the warning, if prompted). Run "dotnet ef migrations remove" again in the command window in the directory that has the project. json file. Alternatively, run "Remove-Migration" command in the package manager console.


2 Answers

Running the following command (obtained from this article) and a response from @Maverik (from StackOverflow here) and a suggestion from @doctor above helped me resolved the issue. Thank you all for your help:

PM> Add-Migration MyFirstMigration -Context BloggingContext 
like image 173
nam Avatar answered Sep 30 '22 20:09

nam


The error clearly explains to mention --context with db Context name if more than one DbContext. So try by mentioning your DbContext name.

dotnet ef migrations add Initial --context SampleDbContext 

Hope this helps.

like image 36
John Avatar answered Sep 30 '22 21:09

John