Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Entity Framework migrations

Assuming that automatic migrations are disabled, if I have for instance, 4 migrations and just the first one was used to update the database:

XXX...XXX_mymigration_v1 - Migration 1
XXX...XXX_mymigration_v2 - Migration 2
XXX...XXX_mymigration_v3 - Migration 3
XXX...XXX_mymigration_v4 - Migration 4
  1. If I run Update-Database it will the Migration 4 applied right?
  2. Intermediate migrations (2 and 3) will be applied in sequence until it reach the migration4?
  3. And after that, if I want to rollback to Migration 1, can I do it?
like image 293
amp Avatar asked Apr 23 '26 13:04

amp


1 Answers

Not sure why no-one has answered this earlier.

1) Yes, update-database with no parameters will update to the latest migration.

2) Migrations are applied in sequence as per the timestamp prefixed to the file name containing the migration.

3) If you want to roll back to the first migration you execute update-database -TargetMigration mymigration_v1. Note that you do not need the timestamp when specifying the migration name.

like image 123
Josh Gallagher Avatar answered Apr 26 '26 05:04

Josh Gallagher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!