【发布时间】:2018-04-07 05:23:03
【问题描述】:
我有一个通过本教程开发的网络应用程序:
本教程使用 EF 和 Code First 将两个 DBContext(ApplicationDbContext 和 MyDBContext)及其各自的数据库放在一起,几个月前我在 Azure 中发布,并且在本地和 Azure 中一切正常。从一开始我就注意到 Azure 只管理一个数据库。在这个数据库中,Azure 是两个 DBContext 的所有表,正如我所说,一切正常。我已经做了几十次迁移,只在我自己的 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));
}
}
然后我实现了:
Enabled-Migrations -ContextTypeName ApplicationDbContext -MigrationsDirectory 迁移\ApplicationDbContext
Add-Migration -ConfigurationTypeName MyWebApp.Migrations.ApplicationDbContext.Configuration "AddFldAspNetUsers"
更新数据库-ConfigurationTypeName MyWebApp.Migrations.ApplicationDbContext.Configuration
本地一切正常,但是当我在 Azure 中发布时出现以下错误:
“/”应用程序中的服务器错误。 支持“ApplicationDbContext”上下文的模型在创建数据库后发生了变化。考虑使用 Code First 迁移来更新数据库
不知道怎么解决,求帮助:
【问题讨论】:
标签: asp.net entity-framework azure entity-framework-migrations