【问题标题】:IdentityDbContext how to run migrationsIdentityDbContext 如何运行迁移
【发布时间】:2015-09-25 07:03:44
【问题描述】:

我是 Entity-Framework-5 和 IdentityDbContext 的新手,我已经成功创建并创建了 AspNet 成员表,然后我更改了模型属性之一中的类型,现在我的项目无法运行并且它告诉我需要运行迁移。我的问题是,如何在 IdentityDbContext 上运行迁移? 我找不到任何关于如何做的好指南。

Additional information: The model backing the 'ApplicationIdentityUserDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

public class ApplicationIdentityUserDbContext : IdentityDbContext<UserProfile> { public ApplicationIdentityUserDbContext() : base("DefaultConnection") { } } 我在运行 enable-migrations 时附加了错误。

【问题讨论】:

  • 运行显示我拥有的 dbContext,当我尝试使用 configtypename 添加迁移时,我收到一条错误消息,告诉我无法在指定的 dbConext 上运行迁移
  • oes not inherit from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. Migrations configuration types must extend from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
  • 您需要为 DBContext 而不是 IdentityContext 类添加迁移。试试这个
  • 当我尝试这样做时,我收到一条错误消息,指出迁移已启用,并且没有尝试 -force 选项,因为我不确定它会对我的 aspnet 成员身份进行更改。跨度>

标签: c# asp.net asp.net-mvc asp.net-mvc-4 entity-framework-5


【解决方案1】:

您可以使用 Package Manager 控制台中的 enable-migrationsadd-migration 命令完成此操作Code First Migrations

这将生成迁移文件,您可以使用 update-database 命令将其应用到数据库(或者它们会根据设置自动运行)。

确保在包管理器控制台中选择正确的默认项目,它应该是包含您的上下文的项目。

【讨论】:

  • 我有两个 DBConext,一个正常,另一个我可以正常运行迁移,我无法添加迁移 IdentityContext 类。
  • 我最终使用 -force 选项来解决我的问题,谢谢,我将答案标记为正确,因为我使用了相同的方法来解决它。
  • 我在 dotnet core 2.2 上遇到了类似的问题,这是由于 Startup.cs 类中的配置错误和设置 json 文件的连接字符串错误。
猜你喜欢
  • 2017-04-03
  • 2012-02-27
  • 1970-01-01
  • 2021-04-27
  • 2017-04-09
  • 1970-01-01
  • 2015-08-28
  • 2015-08-22
  • 2018-07-20
相关资源
最近更新 更多