How to include existing tables into MVC5 IdentityModeld.cs ApplicationDbContext and disable migrations?

StackOverflow https://stackoverflow.com/questions/23149099

Pregunta

Bellow my MVC5 App IdentityModeld.cs:

public class ApplicationUser : IdentityUser {
    public int StaffId { get; set; }
}

//public class ApplicationDbContext : 
//IdentityDbContext<User, UserClaim, UserSecret, UserLogin, Role, UserRole> {
//original: http://www.briankeating.net/?tag=/IdentityDbContext
public class ApplicationDbContext : IdentityDbContext<ApplicationUser> {

    public ApplicationDbContext() : base("DefaultConnection") {
        //Database.SetInitializer<ApplicationDbContext>(null);
        //Configuration.AutoDetectChangesEnabled = false;
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
        //modelBuilder.Ignore<Staff>();
        //base.OnModelCreating(modelBuilder);
    }

    // dublicate from another DbContext
    //public DbSet<Staff> Person { get; set; }
} 

Commented lines cause error:

The model backing the 'ApplicationDbContext' context has changed since the database was created...

I don't need migrations. There are no changes in my database or models. Can I add to existing ApplicationDbContext existing table from database as is? There is no __MigrationHistory table in my database.

¿Fue útil?

Solución

You need to update the shema stored "inside EF" to the current one by adding an empty migration.
Execute the following in the Package Manager Console:

Add-Migration Initial -IgnoreChanges

This should create a new migration with the updated shema for EF, but an empty Up and Down method.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top