Command to perform the Down of a migration

Asked

Viewed 695 times

-1

With the command add-migration created a migration, so is created a class with two functions.

protected override void Up(MigrationBuilder migrationBuilder){...}

protected override void Down(MigrationBuilder migrationBuilder){...}

I know that to execute the Up use the command update-database

The question is how do I perform the command Down to undo the change that was made in the table.

2 answers

3


Just use the

Remove-Migration

He’ll get the latest Add-Migration

before performing the

Update-Database

If you have used the

Update-Database

It will be necessary to redo the changes create a new

Add-Migration

and then rotate the

Update-Database

I stress again that the

Remove-Migration

only works when not yet realized

Update-Database

0

To reverse Migrations you need to perform 3 steps:

first step - To revert to a particular Migration:

Update-Database <nome-da-migration-escolhida>


second step - Delete the Migrations you do not want from the project (they will be deleted automatically in the latest VS2017 versions)


third step - Use the following command to update the database snapshot:

Remove-Migration

Browser other questions tagged

You are not signed in. Login or sign up in order to post.