Code first 在 Entity framework 6 MVC 5 中启用迁移错误
Code first Enable migration error in Entity framework 6 MVC 5
我将 entity framework 6 与 MVC 5 一起使用,并尝试首先在代码中启用迁移,以避免数据丢失。但是当在包管理器控制台中键入命令时,它会抛出以下错误:
PM> Enable-Migrations -ContextTypeName [ContextClassName] The term
'Enable-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
+ Enable-Migrations -ContextTypeName [ContextClassName]
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Enable-Migration:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
我检查了所有重复项,但 none 对我有效。
这里有两种可能的情况。
Entity Framework 未安装或安装不正确。如果你确实有对它的引用,那么首先做:
PM> Uninstall-Package EntityFramework -Force
然后,
PM> Install-Package EntityFramework
确保之后重新启动Visual Studio
您 实际上 使用 Entity Framework 核心,或者您已将 Entity Framework 添加到 ASP.NET 核心项目运行宁关于完整的框架。在任何一种情况下,Entity Framework 包管理器命令中的 none 将可用。如果错误地安装了 EF Core,请将其删除并安装 EF6。如果您有一个 ASP.NET 核心项目,则必须在 EF6 参考的完整框架上添加一个控制台应用程序或 class 库 运行ning。您将在此处管理您的所有实体,以及 运行 您针对该项目的包管理器命令。这样做的原因是 EF6 包管理器命令与 ASP.NET 核心不兼容,即使您 运行 正在使用完整框架也是如此。
我将 entity framework 6 与 MVC 5 一起使用,并尝试首先在代码中启用迁移,以避免数据丢失。但是当在包管理器控制台中键入命令时,它会抛出以下错误:
PM> Enable-Migrations -ContextTypeName [ContextClassName] The term 'Enable-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 + Enable-Migrations -ContextTypeName [ContextClassName] + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Enable-Migration:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
我检查了所有重复项,但 none 对我有效。
这里有两种可能的情况。
Entity Framework 未安装或安装不正确。如果你确实有对它的引用,那么首先做:
PM> Uninstall-Package EntityFramework -Force
然后,
PM> Install-Package EntityFramework
确保之后重新启动Visual Studio
您 实际上 使用 Entity Framework 核心,或者您已将 Entity Framework 添加到 ASP.NET 核心项目运行宁关于完整的框架。在任何一种情况下,Entity Framework 包管理器命令中的 none 将可用。如果错误地安装了 EF Core,请将其删除并安装 EF6。如果您有一个 ASP.NET 核心项目,则必须在 EF6 参考的完整框架上添加一个控制台应用程序或 class 库 运行ning。您将在此处管理您的所有实体,以及 运行 您针对该项目的包管理器命令。这样做的原因是 EF6 包管理器命令与 ASP.NET 核心不兼容,即使您 运行 正在使用完整框架也是如此。