Asp.Net两个本地DBContexts到一个Azure DBContext

时间:2017-10-26 00:22:11

标签: asp.net entity-framework azure ef-migrations

我有一个通过本教程开发的网络应用程序:

https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/introduction-and-overview

本教程将两个DBContext(ApplicationDbContext和MyDBContext)及其各自的数据库与EF和Code First放在一起,几个月前我在Azure上发布了一切,本地和Azure都运行良好。从一开始我就注意到Azure只管理一个数据库。在这个数据库中,Azure是两个DBContexts的所有表,正如我所说的一切正常。我已经完成了几十次迁移,只在我自己的WebApp表(MyDBContext)

中完成

现在我想将字段添加到AplicationDBContext的表中,特别是AspNetUser表,所以我修改了以下代码

public class ApplicationUser: IdentityUser
{
    /// My New Field
    public bool Disabled {get; set; }

    public ClaimsIdentity GenerateUserIdentity (ApplicationUserManager manager)
    {
        var userIdentity = manager.CreateIdentity (this, DefaultAuthenticationTypes.ApplicationCookie);
        return userIdentity;
    }

    public Task <ClaimsIdentity> GenerateUserIdentityAsync (ApplicationUserManager manager)
    {
        return Task.FromResult (GenerateUserIdentity (manager));
    }
}

然后我实施了:

已启用 - 迁移-ContextTypeName ApplicationDbContext -MigrationsDirectory Migrations \ ApplicationDbContext

Add-Migration -ConfigurationTypeName MyWebApp.Migrations.ApplicationDbContext.Configuration&#34; AddFldAspNetUsers&#34;

Update-Database -ConfigurationTypeName MyWebApp.Migrations.ApplicationDbContext.Configuration

本地一切正常,但是当我在Azure中发布时,我收到以下错误:

&#39; /&#39;中的服务器错误应用 支持&#39; ApplicationDbContext&#39;的模型自创建数据库以来,上下文已更改。请考虑使用“代码优先迁移”来更新数据库

我不知道如何解决,我需要帮助:

1 个答案:

答案 0 :(得分:0)

我最近遇到了同样的问题。您支持迁移但尚未更新Azure中的Identity数据库表的问题背后的原因。

请遵循以下几点

  • 在发布之前,在发布窗口中转到设置,您可以 在Databases部分下找到ApplicationDbContext。
  • 勾选复选框执行代码首次迁移(运行时) 应用程序启动)选项。尝试重新发布它。 :)
相关问题