简体   繁体   English

ASP.NET Core EF Add-Migration 命令不起作用

[英]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注意事项

  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.我正在使用上述教程,但我使用的是Individual User Account身份验证而不是教程中使用的No Authentication
  2. I've latest release of ASP.NeT Core 1.0 and VS2015-Update 3 on windows 8.1ASP.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. This is a freshly created project.这是一个新创建的项目。 No other DbContext was manually installed没有手动安装其他 DbContext

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注意事项

  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.我使用上面的教程,但我使用的是Individual User Account身份验证,而不是本教程中使用的“ No Authentication ”。
  2. I've latest release of 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最新版本
  3. This is a freshly created project.这是一个新创建的项目。 No other DbContext was manually installed没有其他手动安装的DbContext

[--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.

相关问题 添加迁移在 asp.net 核心中不起作用 - Add-Migration not working in asp.net core .net核心EntityFramework“添加迁移”无效 - .net core EntityFramework “Add-Migration” not working EF7 .NET Core 1 RC2添加迁移失败 - EF7 .NET Core 1 RC2 Add-Migration failing ASP.NET Core WebApi Add-Migration Entity Framework Core - ASP.NET Core WebApi Add-Migration Entity Framework Core ASP.Net Core/EF Core:在身份用户类和自定义定义类之间具有多对多关系的添加迁移后的堆栈溢出 - ASP.Net Core/EF Core: Stack overflow after add-migration with many-to-many relationship between an Identity User class and a custom defined class 按字母顺序添加迁移创建的列Asp.Net Core 2.0 - Add-Migration Created Columns Alphabetically Asp.Net Core 2.0 EF Core 迁移错误:PositionalParameterNotFound,Add-Migration - EF Core migration error: PositionalParameterNotFound,Add-Migration EF Core 1.1到WebApi核心 - 添加迁移失败 - EF Core 1.1 to WebApi Core - Add-Migration fails 如何在EF Core中添加自定义添加迁移行为? - How to add custom Add-Migration behaviour in EF Core? 是否有执行与添加迁移相同的 function 的 EF Core Package 管理器控制台命令<name> EF6 中的 -IgnoreChanges 命令</name> - Is there an EF Core Package Manager Console command that performs the same function as the Add-Migration <name> -IgnoreChanges command in EF6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM