[英]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:当我在从同一教程创建的 VS2015 项目中运行PM> Add-Migration MyFirstMigration
命令时,按照此Microsoft 教程,我收到以下无法解决的错误:
More than one DbContext was found.找到了多个 DbContext。 Specify which one to use.指定使用哪一个。
Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.对 PowerShell 命令使用“-Context”参数,对 dotnet 命令使用“--context”参数。
Point to note注意事项
Individual User Account
authentication instead of No Authentication
used in the tutorial.我正在使用上述教程,但我使用的是Individual User Account
身份验证而不是教程中使用的No Authentication
。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
有最新版本的ASP.NeT Core 1.0 and VS2015-Update 3 on windows 8.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.运行以下命令(从本文中获得)和@Maverik(来自此处的StackOverflow)的响应以及上面@doctor 的建议帮助我解决了这个问题。 Thank you all for your help:谢谢大家的帮助:
PM> Add-Migration MyFirstMigration -Context BloggingContext
The error clearly explains to mention --context with db Context name if more than one DbContext.如果有多个 DbContext,该错误清楚地解释了要提及 --context 和 db Context 名称。 So try by mentioning your DbContext name.因此,请尝试提及您的 DbContext 名称。
dotnet ef migrations add Initial --context SampleDbContext
Hope this helps.希望这会有所帮助。
If you need only update a identity schema existent, try it:如果您只需要更新现有的身份架构,请尝试:
update-database -Context ApplicationDbContext
ApplicationDbContext = your identity context ApplicationDbContext = 您的身份上下文
that because you have two DbContext in your solution.那是因为您的解决方案中有两个 DbContext。 First is default created when you creating project(ApplicationDbContext) and second your EF DbContext.第一个是创建项目(ApplicationDbContext)时默认创建的,第二个是 EF DbContext。 Solution is described in error message just specify your EF DbContext错误消息中描述了解决方案,只需指定您的 EF DbContext
Add-Migration MyFirstMigration -Context DbContextName
它在我的项目中有效。
Use below to commands:使用下面的命令:
PM> Add-Migration MyFirstMigration -Context YourDbContext PM> Add-Migration MyFirstMigration -Context YourDbContext
PM> update-database -Context YourDbContext PM> 更新数据库 -Context YourDbContext
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:当我在从同一教程创建的VS2015项目中运行PM> Add-Migration MyFirstMigration
命令时,遵循此Microsoft教程,我得到以下无法解决的错误:
More than one DbContext was found.找到了多个DbContext。 Specify which one to use.指定要使用的一个。
Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.对于PowerShell命令使用'-Context'参数,对于dotnet命令使用'--context'参数。
Point to note注意事项
Individual User Account
authentication instead of No Authentication
used in the tutorial.我使用上面的教程,但我使用的是Individual User Account
身份验证,而不是本教程中使用的“ No Authentication
”。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
发布了ASP.NeT Core 1.0 and VS2015-Update 3 on windows 8.1
最新版本[--context] [ - 语境]
The DbContext class to use.要使用的 DbContext 类。 Class name only or fully qualified with namespaces.仅类名或使用命名空间完全限定。 If this option is omitted, EF Core will find the context class.如果省略此选项,EF Core 将查找上下文类。 If there are multiple context classes, this option is required.如果有多个上下文类,则需要此选项。
Add-Migration MyMigration -context DataContextName
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.