【问题标题】:cannot use add-Migration in .net core 2.1 project using visual studio for mac无法在使用 Visual Studio for Mac 的 .net core 2.1 项目中使用 add-Migration
【发布时间】:2021-04-04 02:19:33
【问题描述】:

我正在使用 Visual Studio for Mac 并拥有 .NET Core 2.1 项目。我在使用“Add-Migration”之类的迁移命令时遇到问题,即出现以下错误:

**Add-Migration : The term ‘Add-Migration’ is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
 + Add-Migration DBUpdates -Context applicationdbcontext
 + ~~~~~~~~~~~~~
 + CategoryInfo         : ObjectNotFound: (Add-Migration:String) [], CommandNotFoundException
 + FullyQualifiedErrorId : CommandNotFoundException**

你知道这可能是什么原因吗?

【问题讨论】:

  • Add-Migration 来自 EF 6,而不是来自 EF Core,因此它不起作用是完全有道理的。请阅读docs.microsoft.com/en-us/ef/core/cli/…
  • 你需要添加正确的nuget包。相信它的实体框架核心工具
  • @CamiloTerevinto 如果在 Visual Studio 中调用,则添加迁移在 EF Core 中是正确的。见docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/…
  • @ahmedGaber。您是从 Visual Studio 还是从命令行运行添加迁移?
  • 感谢 Visual Studio 的 @Julian 回复,现在卸载并安装 Microsoft.EntityFrameworkCore.Tools 后正在工作

标签: asp.net-core entity-framework-core database-migration entity-framework-migrations visual-studio-mac


【解决方案1】:

此错误表示缺少一个包。

从 nuget 安装包 Microsoft.EntityFrameworkCore.Tools。然后重新打开视觉工作室。

【讨论】:

  • 卸载再安装Microsoft.EntityFrameworkCore.Tools并重启visual studio解决问题
【解决方案2】:

您可能缺少 nuget 包,如果不是这种情况,还请仔细检查 Visual Studio 中的 powershell 接口是否指向正确的项目(您想要存在并定义 DbContext 对象的那个)

【讨论】:

    猜你喜欢
    • 2017-05-23
    • 2021-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2018-05-07
    • 2021-11-17
    • 2022-09-30
    相关资源
    最近更新 更多