EF 6 Code First Migration after deleting data from __MigrationHistory table

asp.net-mvc entity-framework entity-framework-6

Question

I have accidentally deleted data from __MigrationHistory table and I tried to make migration new tables and column changes to db. At this time EF6 show me an error

"There is already an object named 'xxxx' in the database.".

I tried the way by using this command and there is no effect on table column changes.

Add-Migration MyMigration1 -IgnoreChanges
Update-database -Force

There are many recommendation about this for recreating db or another else. But those ways might be effect data losing to my db which contains a huge size of tested data and I can't able to lost any data. How to solve this error by without losing any data. If anybody please...

Update

Finally I found the solution to solve my problem. I am not sure it's a prefer way to solve such kind of problems but it's worked for me.

I cleaned data from __MigrationHistory table,tried to migrate new db and I copied data from __MigrationHistory of new db to my old db, then I set AutomaticMigration true and run update-database command and the problem was solved.

1
0
9/7/2018 7:25:20 AM

Popular Answer

I'm not sure if its good approach to fix that but it worked for me.

I just did insert into that table with proper version and names of the already applied migrations, I did it in EF Core and it works actually, but please wait for somebody to comfirm that what im writing about.

The problem I see there is that you need two more fields to be filled (in EF Core theres only two columns) but I think that you can receive them using for example SQL Profiler

0
9/5/2018 7:28:55 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow