【发布时间】:2015-01-29 17:10:02
【问题描述】:
我在“开箱即用”ApplicationUser 类中添加了一个名为 ResetPassword 的新属性,但是当我运行“add-migration”时,自动生成的迁移类中的 up/down 方法是空白的,当我尝试登录时应用程序引发以下错误“支持 'ApplicationDbContext' 上下文的模型自创建数据库以来已更改。考虑使用 Code First 迁移来更新数据库”。
这是我的代码:
public class ApplicationUser : IdentityUser
{
public bool ResetPassword { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
// 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();
}
}
可能 DAL 类如下所示:
public class DefaultConnection : DbContext
{
public DefaultConnection()
: base("DefaultConnection")
{
this.Configuration.ProxyCreationEnabled = false;
this.Configuration.LazyLoadingEnabled = false;
}
public DbSet<Category> Categories { get; set; }
public DbSet<Group> Groups { get; set; }
public DbSet<Model> Models { get; set; }
public DbSet<Variable> Variables { get; set; }
public DbSet<Column> Columns { get; set; }
public DbSet<Project> Projects { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<Config> Configs { get; set; }
public DbSet<Target> Targets { get; set; }
public DbSet<Organisation> Organisations { get; set; }
public DbSet<OrgGroup> OrgGroups { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
登录时,这是引发错误的行:
var userManager = context.OwinContext.GetUserManager();
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-5 entity-framework-migrations asp.net-identity-2