ASP.NET Core EF Add-Migration command not working

C#Visual Studio-2015asp.net CoreEntity Framework-Core

C# Problem Overview


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

C# Solutions


Solution 1 - C#

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

Solution 2 - C#

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.

Solution 3 - C#

If you need only update a identity schema existent, try it:

update-database -Context ApplicationDbContext

ApplicationDbContext = your identity context

Solution 4 - C#

that because you have two DbContext in your solution. First is default created when you creating project(ApplicationDbContext) and second your EF DbContext. Solution is described in error message just specify your EF DbContext

Solution 5 - C#

Add-Migration MyFirstMigration -Context DbContextName

It does work in my project.

Solution 6 - C#

Use below to commands:

> PM> Add-Migration MyFirstMigration -Context YourDbContext > > PM> update-database -Context YourDbContext

Solution 7 - C#

[--context]

> The DbContext class to use. Class name only or fully qualified with > namespaces. If this option is omitted, EF Core will find the context > class. If there are multiple context classes, this option is required.

Add-Migration MyMigration -context DataContextName

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnamView Question on Stackoverflow
Solution 1 - C#namView Answer on Stackoverflow
Solution 2 - C#JohnView Answer on Stackoverflow
Solution 3 - C#Diego VenâncioView Answer on Stackoverflow
Solution 4 - C#Mohammad Al SafraView Answer on Stackoverflow
Solution 5 - C#Mohsen.bakhtiyarihaView Answer on Stackoverflow
Solution 6 - C#Harichandra SagarView Answer on Stackoverflow
Solution 7 - C#Arshman SaleemView Answer on Stackoverflow