revert migration ef core code example

Example 1: ef remove migration

/*to remove the last migration:*/
/*Visual Studio:*/
Remove-Migration
/*.Net Core CLI:*/
dotnet ef migrations remove

Example 2: how to remove last migration in ef core

* CLI
dotnet ef migrations remove

*Package Manager Console
PM> Remove-Migration

Example 3: enable migration in .net core

dotnet ef migrations add InitialCreate

Example 4: ef rollback migration

//EF 6.4 
//PM> Update-Database -TargetMigration:"NameOfSecondToLastMigration"

Example 5: The migration '20200806160941_InitialMigration' has already been applied to the database. Revert it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration.

dotnet ef database update 0
dotnet ef migrations remove

Tags:

Sql Example