gpt4 book ai didi

c# - 无法运行启用迁移 VS2013 SP4

转载 作者:太空宇宙 更新时间:2023-11-03 23:47:12 24 4
gpt4 key购买 nike

我正在使用 VS2013 Community Edition 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

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

  • 打开解决方案
  • 清洁和重建解决方案
  • 重新启动 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

关于c# - 无法运行启用迁移 VS2013 SP4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27233726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com