Rollback of Migrations in Entity Framework Core (Managed through code)

Опубликовано: 29 Сентябрь 2024
на канале: DotNet Core Central
4,427
26

In this video I am going to cover the following main topics:
1. Creating a change to the table schema through Entity Framework Core Migrations
2. Rollback of migrations to a particular version through Entity Framework Core Migrations

In my previous video, I covered how to use Entity Framework Migrations, to create a table through code here:    • Migrations in Entity Framework Core (...  . I would strongly suggest the watch this video to get a context.

For rolling back to a previous version of the migration, we cannot use the Database.Migrate method. Instead, we will have to use Database.GetService to get an instance of IMigrator And then call the IMigrator.Migrate method.

The source code for this solution is available in GitHub here: https://github.com/choudhurynirjhar/e...

For Migration Up and Down to work through code, the class names cannot contain _, which I figured out the hard way. As long as we follow normal class naming, it should be fine. For the migration id we can use any conversion we want. And the file name of the migration class can be the same as the id, but its a personal preference.