Remapping ApplicationUser to a new table

Apr 9, 2014 at 5:42 PM
Hi,

I've repointed the ApplicationUser class to an existing table that I already had in my DB through normal EF means (Persons instead of AspNetUsers). I did this by putting the following line in my OnModelCreating method:

modelBuilder.Entity<ApplicationUser>().ToTable("Persons").Property(p => p.Id).HasColumnName("PersonId");

However, when I call add-migration some_name_here, the migration that is created is trying to do the following:

public override void Up()
{
  RenameTable(name: "dbo.Person", newName: "Persons");
}

The problem is, there is not (and never has been) a table named "Person" - it has always been Persons (because EF likes to pluralize table names by default). So, here I am stuck...I can't call update-database because it fails since "dbo.Person" doesn't exist, and I can't run the app because it keeps complaining that the model that backs the context is out of sync.

I've tried deleting the database and this "faulty" migration above, then re-running the migrations from the "initial" up through the one just prior to this faulty one (which works fine) but then I still get the message that I need to call add-migration and it generates the same faulty migration again.

Where is it getting this notion that it needs to rename a non-existent table? And any ideas on how to bypass this?

I work with a team, so wiping out all of my migrations and the database and then re-enabling migrations is far from ideal (and probably still wouldn't solve my problem).
Jul 24, 2014 at 4:41 AM
Edited Jul 24, 2014 at 4:42 AM
Did you tried editing your Up() script ?