Is it possible to remove an EF Core Database migration after the database is updated with the same
Yes, it's possible, but only if it is the last migration or if you revert all migrations after it.
To revert all migrations including the desired, use the -Migration parameter of the same Update-Database
command and pass the name/id of the migration before the desired (or special value 0
if it is the first)
Update-Database MigrationBeforeTheOneYouWantToRevert
For more info, see Applying Migrations - Command-line tools sections of the official EF Core documentation.
How to rollback more than one EF Core migration at time
The solution is to update the database back to the target migration desired:
dotnet ef database update "THE NAME OF THE TARGET MIGRATION"
Execute this Ef Core command multiple time until the desired migration:
dotnet ef migrations remove
And below my Powershell script:
param (
[Parameter(Mandatory=$true)][string]$migration,
[Parameter(Mandatory=$true)][int]$nbr_removes
)
dotnet ef database update $migration
for($i=0; $i -lt $nbr_removes; $i++) {
dotnet ef migrations remove
echo 'revert changes'
}
And we can use it like below:
.\rollback_to.ps1 2019081200218_AddScoreColumn 2
EF Core migration to remote database
So I was just using the wrong environment declaration. Run this before the update:
$env:ASPNETCORE_ENVIRONMENT = 'Production'
Related Topics
How to Catch All Exceptions/Crashes in a .Net App
Datagridview: How to Set a Cell in Editing Mode
Convert Datetime to Julian Date in C# (Tooadate Safe)
How to Xml-Serialize a Dictionary
How to Get the Value of Private Field Using Reflection
Linq Join Iquery, How to Use Defaultifempty
ASP.NET Web Application Message Box
How to Get the Index of the Highest Value in an Array Using Linq
Is the C# Compiler Smart Enough to Optimize This Code
How to Bring Up the Built-In File Copy Dialog
Getting All Possible Combinations from a List of Numbers