无法运行启用迁移 VS2013 SP4



我正在使用VS2013社区版SP4创建一个MVC 5网站。它使用 EntityFramework v6 我正在尝试通过添加辅助表来保存其他数据来扩展默认的 AspNetUsers 数据库,但是当我尝试运行Enable-Migration时出现此错误:

Enable-Migration : 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-Migration
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Enable-Migration:String) [], 
                              CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我尝试了谷歌搜索建议的以下补救措施:

  • 打开解决方案
  • 清洁和重建解决方案
  • 重新启动VS2013
  • 删除并重新安装 NuGet
  • 运行Install-Package EntityFramework -IncludePrerelease命令
  • 确保VS2013以管理员身份运行

还有什么我可以尝试的吗?

谢谢!

正确的术语是 enable-migrations

以下是从我对类似问题的回答中复制粘贴的其他一些有用信息。

add-migration InitialCreate

这将创建迁移。InitialCreate实际上是一个字符串,你可以把它改成你想要的任何内容。此命令将生成从 strach 创建数据库所需的脚本。

update-database

此命令验证数据库并应用使数据库保持最新所需的迁移(或迁移 - 可能有多个迁移(。

这是初始设置。如果对第一个代码优先类进行进一步更改或添加更多,则只需添加新的迁移,然后执行它。

add-migration AddedFirstName
update-database

就是这么简单!

有一些更高级的概念,如种子、回滚、更新到特定迁移等,但我上面键入的内容涵盖了迁移的基础知识和日常用法。

我建议您阅读这篇文章,其中更详细地解释了所有内容:http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application

最新更新