2
我添加了一個名爲ResetPassword的新屬性給「開箱即用」的ApplicationUser類,但是當我運行「add-migration」時,自動生成的遷移類中的向上/向下方法是空白的,當我嘗試登錄到應用程序會引發以下錯誤:「創建數據庫後,支持」ApplicationDbContext「上下文的模型已更改。請考慮使用Code First Migrations來更新數據庫」。爲什麼我的擴展標識帳戶未能自動遷移到AspNetUsers表?
這是我的代碼:
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 =上下文.OwinContext.GetUserManager();