Thursday, November 26, 2015

Resetting migrations when using Code First Migrations in MVC

  1. Delete all the migrations folder in your project except Configuration.cs
  2. Move Configuration.cs to some place safe and remove from the migrations folder
  3. Delete the records in the __MigrationHistory table in your database
  4. Then run the following command in the Package Manager Console:
    >Enable-Migrations -EnableAutomaticMigrations -Force
    NOTE: This will recreate your Configuration.cs
  5. Replace the new Configuration.cs with the Configuration.cs that we moved to a safe place earlier
  6. Then run the following command in the Package Manager Console:
    >Add-Migration Reset
    NOTE: The name is not important
  7. This will create a file in the migrations folder.
  8. Open the new migration file and comment out all the code in the Up() method such that the body of the method is just commented out code.
  9. Save and Build the project
  10. Then run the following command in the Package Manager Console:
    >Update-Database
  11. Uncomment the Up() method.
  12. Save and Build the project.



No comments: