ASP.NET Core EF Add-Migration命令无法正常工作

当我在从同一教程创建的VS2015项目中运行PM> Add-Migration MyFirstMigration命令时,遵循此Microsoft教程 ,我得到以下错误,我无法解决:

 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. 

值得注意的

  1. 我正在使用上面的教程,除了我正在使用Individual User Account身份validation而不是本教程中使用的No Authentication
  2. ASP.NeT Core 1.0 and VS2015-Update 3 on windows 8.1发布了最新版本的ASP.NeT Core 1.0 and VS2015-Update 3 on windows 8.1
  3. 这是一个新创建的项目。 没有手动安装其他DbContext

运行以下命令(从本文获得)和来自@Maverik的响应(来自STackoverflow)以及来自@doctor的建议帮助我解决了这个问题。 感谢大家的帮助:

 PM> Add-Migration MyFirstMigration -Context BloggingContext 

因为你的解决方案中有两个DbContext。 首先是创建项目(ApplicationDbContext)时创建的默认值,然后是EF DbContext的第二个。 错误消息中描述了解决方案,只需指定您的EF DbContext

如果有多个DbContext,错误清楚地解释了 – 带有db Context名称的–context。 因此,请提及您的DbContext名称。

 dotnet ef migrations add Initial --context SampleDbContext 

希望这可以帮助。