Reputation: 31
I added a new property called ResetPassword to the "out of the box" ApplicationUser class but when I run "add-migration" the up/down methods in the auto generated migration class are blank and when I try to log on to the application the following error is raised "The model backing the 'ApplicationDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database".
This is my code:
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();
}
}
May DAL class looks like this:
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>();
}
}
When logging on this is the line which throws the error:
var userManager = context.OwinContext.GetUserManager();
Upvotes: 2
Views: 111
Reputation: 35106
You have 2 contexts in your application. When you run migrations, you need to specify type of context you want migration for:
Add-Migration -configuration <Namespace>.ApplicationDbContext <Migrations-Name>
See this page for more details about using migrations with multiple DbContexts in the same assembly.
Upvotes: 0