Resetting migrations when using Code First Migrations in MVC
- Delete all the migrations folder in your project except Configuration.cs
- Move Configuration.cs to some place safe and remove from the migrations folder
- Delete the records in the __MigrationHistory table in your database
- Then run the following command in the Package Manager Console:
>Enable-Migrations -EnableAutomaticMigrations -Force
NOTE: This will recreate your Configuration.cs
- Replace the new Configuration.cs with the Configuration.cs that we moved to a safe place earlier
- Then run the following command in the Package Manager Console:
>Add-Migration Reset
NOTE: The name is not important
- This will create a file in the migrations folder.
- 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.
- Save and Build the project
- Then run the following command in the Package Manager Console:
>Update-Database
- Uncomment the Up() method.
- Save and Build the project.
No comments:
Post a Comment