When I add-migration, Up and Down method are generated.
and I know when I update database (update-database), it runs the Up method.
How about Down method?
when it will run, is it for rollback? and, how can I run it?
Its for when you want to "downgrade" the database to a previous migration state. You use it with the -TargetMigration
flag of the Update-Database
command. For example, if you have added the following migrations:
You can revert the database to the Initial migration state by:
Update-Database -TargetMigration:Initial
In which case the code in the Down()
methods of the SecondMigration
and FirstMigration
classes will run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With