ASP.NET Core EF Add-Migration command not working

有些话、适合烂在心里 提交于 2019-12-04 09:53:39

问题


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

回答1:


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



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/38162227/asp-net-core-ef-add-migration-command-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!