Removing code first migration and degrade to older state

 28-Jul-2014   nityaprakash     EntityFramework  code-first-migration    Comments  0

Yesterday I came across a scenario where I have added a new migration folder also updated migration with code first migration process. I did following thing to understand the scenario:

  • Created new DBContext class and added few classes.
  • Added a new migration folder.

  • And executed the Update-database command to migrate changes in database.

But, later I realize that I don't need this migration and want to revert it back. I thought, I should delete all migration folder and manually revert the database.

Manually update may lead to database corruption issue and your later migration may not work, even current database operation may not work properly.

So decided to revert from code migration only. As I wanted to revert all db changes done for newly added migration. After few failure I was successfully able to downgrade the database with following command in Nuget Package Manager Console:


Update-Database -ConfigurationType DnpMVCSite.Migrations.QuestionMigration.Configuration –TargetMigration:$InitialDatabase

It completed with following output:

I hope it might helpful for someone.


Nitya Prakash Sharma has over 10 years of experience in .NET technology. He is currently working as Senior Consultant in industry. He is always keen to learn new things in Technology and eager to apply wherever is possible. He is also has interest in Photography, sketching and painting.

My Blog
Post Comment

COMMENTS