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

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

문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top