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

时间:2016-07-02 16:28:20

标签: c# visual-studio-2015 asp.net-core entity-framework-core

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

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身份验证,而不是本教程中使用的No Authentication
  2. 我最新发布的ASP.NeT Core 1.0 and VS2015-Update 3 on windows 8.1
  3. 这是一个新创建的项目。没有手动安装其他DbContext

7 个答案:

答案 0 :(得分:35)

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

PM> Add-Migration MyFirstMigration -Context BloggingContext

答案 1 :(得分:11)

如果仅需要更新现有的身份模式,请尝试:

update-database -Context ApplicationDbContext

ApplicationDbContext =您的身份上下文

答案 2 :(得分:7)

如果有多个DbContext,错误清楚地解释了 - 带有db Context名称的上下文。所以请提一下你的DbContext名称。

dotnet ef migrations add Initial --context SampleDbContext

希望这有帮助。

答案 3 :(得分:4)

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

即可

答案 4 :(得分:2)

Add-Migration MyFirstMigration -Context DbContextName

它确实可以在我的项目中工作。

答案 5 :(得分:1)

使用下面的命令:

<块引用>

PM> Add-Migration MyFirstMigration -Context YourDbContext

PM> 更新数据库 -Context YourDbContext

答案 6 :(得分:0)

在项目中拥有多个上下文是否可以?我问在使用个人用户帐户身份验证在我的项目中有两个DbContext时是否正常。

相关问题