我正在使用实体框架代码在MVC中首次迁移,以在Azure SQL服务器上创建数据库。在创建新的Web应用程序时,我选择了“ASP.NET 4.5.2模板”中的“MVC”,并选中了“Authentication = Individual User Accounts”和“Host in the cloud”。
我的IdentityModels.cs看起来像这样 -
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
// I added this method to create a mapping using fluent APIs to fix some error I was getting while updating migration.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId);
modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id);
modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId });
// modelBuilder.Entity<CloudUnitLib.UnitOfMeasure>().HasKey(k => k.UnitId);
}
}
我添加了表格“MyTable-1”,“MyTable-2”,“MyTable-3”&amp; “MyTable-4”到数据库。运行应用程序LOCALLY,它在本地数据库中创建了以下表 - dbo._MigrationHistory,dbo.ApplicationUsers,dbo.IdentityRoles,dbo.IdentityUserClaims,dbo.IdentityUserLogins,dbo.IdentityUserRoles以及最后由我添加的表格“MyTable-1”,“MyTable-2”,“MyTable-3”&amp; “MyTable的-4”。
当我在云上发布Web应用程序时出现问题。它在Azure数据库中创建了以下表 - dbo._MigrationHistory,dbo.AspNetRoles,dbo.AspNetUserClaims,dbo.AspNetUserLogins,dbo.AspNetUserRoles,dbo.AspNetUsers。
问题3:当我尝试使用以下一系列命令更新数据库时,它会尝试删除带有名称的表 “IdentityXXXX”,显然不存在于服务器中 数据库,并抛出错误!如何解决这个问题?
问题4:我添加的所有“MyTable-X”表都没有添加到服务器数据库中。为什么呢?
因为本地数据库中存在所有表,所以当我在本地运行它时,应用程序运行得非常好。但它不能在服务器上运行。
我将不胜感激任何帮助。我真的很困惑。
谢谢