So to rollback to B you could use either: Update-Database -TargetMigration:"B"Īccording to this related answer on a similar question, correct command is -Target for EF Core 1.1 while it is -Migration for EF Core 2.0. Package Manager Console PM > add- migration MyFirstMigration Nu s dng lnh dotnet Command Line Interface. Likewise, if you have applied migrations A, B, C, D, and E (in that order), then the ordinal 1 should refer to A, ordinal 2 should refer to B, and so on. M Package Manager Console t Tools -> NuGet Package Manager -> Package Manager Console. We'll see how to do this in just a second, but first we need to update the database. That's right, you can use Migrations to rollback changes made to your database. enable-migrations EnableAutomaticMigration: true Once the command runs successfully, it creates an internal sealed Configuration class derived from DbMigrationConfiguration in the Migration folder in your project. So in that case, you have to use the 0 (ordinal) value. The Down () method is more interesting though, because it is used to rollback a migration. To use Automated Migration, run the following command in the Package Manager Console. If you want to rollback all migrations and start over, you can use: Update-Database -Target:0Ġ, above, would rollback even the FIRST migration ( this is a destructive command-be sure you know what you're doing before you use it!)-something you cannot do if you use the syntax above that requires the name of the target migration (the name of the 0th migration doesn't exist before a migration is applied!). Thus, if you use GET-MIGRATIONS and you find that you have A, B, C, D, and E, then using this command will rollback E and D to get you to C: Update-Database -TargetMigration:"C"Īlso, unless anyone can comment to the contrary, I noticed that you can use an ordinal value and the short -Target switch (thus, -Target is the same as -TargetMigration). ![]() What you are doing above is saying that you want to rollback all migrations UNTIL you're left with the migration specified. Remove-Migration In the dotnet CLI, the equivalent command would be the following: dotnet ef migrations remove Note: If you have more than one Data Context, it is mandatory that you specify in the previous command the name of the Data Context to be used. Add-Migration: Creates a new migration class as per specified name with the Up () and Down () methods. I want to add some clarification to this thread: Update-Database -TargetMigration:"name_of_migration" In order to use code-based migration, you need to execute the following commands in the Package Manager Console in Visual Studio: Enable-Migrations: Enables the migration in your project by creating a Configuration class.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |