ceci
ceci

Reputation: 429

Rollback to a specific migration

What are the steps for rolling back to specific migration state.

I want to remove the field Url....so I ran the command below.

Update-Database –TargetMigration: AddUrl

The column name on the db table was successfully removed but it was added back when I ran the application.

Do I manually remove the '201504212002469_AddUrl' file under the Migrations folder and everything else that was added?

Upvotes: 1

Views: 533

Answers (2)

Roman Pushkin
Roman Pushkin

Reputation: 6079

You don't need to delete any records from __MigrationHistory.

Just roll back to your previous migration. So if you have two migrations:

201504212002468_Something
201504212002469_AddUrl

Run

Update-Database --TargetMigration:Something

After that you can remove 201504212002469_AddUrl.cs and other related files from the project.

Upvotes: 3

Dmitry Sadakov
Dmitry Sadakov

Reputation: 2158

Remove the automatic update to latest migrations by removing the MigrateDatabaseToLatestVersion initializer, example:

   Database.SetInitializer(
       new MigrateDatabaseToLatestVersion<BlogContext, Configuration>())

Upvotes: 0

Related Questions