0

I am using Entity Framework 7 and I would like to rename

"__EFMigrationsHistory" 

table name to

"__Migrations".

So I have the following on my context:

protected override void OnModelCreating(ModelBuilder builder) {

  base.OnModelCreating(builder);

  builder
     .Entity<HistoryRow>()
     .ToTable("__Migrations")
     .HasKey(x => x.MigrationId);

  // Remaining configuration

}

I am able to create the migration but when I apply it to the database I get:

There is already an object named 'PK_HistoryRow' in the database.
Could not create constraint or index. See previous errors.

I have been trying a few options but I always end with a problem.

Does anyone knows the best way to do this?

Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
  • Are you in a position where you can delete your migrations folder and drop the database? – JsonStatham Feb 22 '16 at 11:55
  • Yes, I am on the project start. I can delete the entire database. The project is only on my developing machine. Not live yet. That is why I want to do it now. – Miguel Moura Feb 22 '16 at 11:56
  • I would delete the migrations folder completely, and start again with the above config set. Follow this link to reset migrations http://stackoverflow.com/questions/11679385/reset-entity-framework-migrations – JsonStatham Feb 22 '16 at 11:59
  • Make sure you delete the database too and hopefully when you run the application the table name will be as you wish if this is a code first application. – JsonStatham Feb 22 '16 at 12:01
  • Yes, this is a code first application using Entity Framework 7 (not 6). I deleted the migrations folder and the database, recreated the migration and the database and got the same error ... No idea why. – Miguel Moura Feb 22 '16 at 12:14
  • BTW, in Entity Framework 7 to reset migrations: http://stackoverflow.com/questions/32009617/reset-entity-framework-7-migrations – Miguel Moura Feb 22 '16 at 12:15
  • @MiguelMoura Its an old question but if you have updated to ASP.NET CORE 1.0.0, you can see [this](http://stackoverflow.com/questions/38507861/entity-framework-core-change-schema-of-efmigrationshistory-table/38521439#38521439) – tmg Jul 22 '16 at 09:39

0 Answers0