Migrating an Asp.net database, what is the Down method used for?

When I add-hyphen, Up and Down methods are generated.

and I know when I update the database (update-database), it runs the Up method.

What about the Down method?

when it will be launched, is it for rollback? and how can i run it?

+4
source share
1 answer

Its for when you want to "downgrade" a database to a previous migration state. You use it with the -TargetMigrationteam flag Update-Database. For example, if you added the following migrations:

  • Initial
  • Firstmigration
  • SecondMigration (current state)

You can return the database to the initial state of migration with:

Update-Database -TargetMigration:Initial

Down() SecondMigration FirstMigration.

+8

Source: https://habr.com/ru/post/1547053/


All Articles