sql-serverentity-framework-coreef-core-2.0

How to revert EF Core migration from SQL Server 2016 production machine


I have to revert the last EF Core migration from a productive instance from a SQL Server 2016 with no Visual Studio installed. How to do this?

Note: I already tried to install .NET SDK on the server but nevertheless it does not know the command dotnet ef. Executing the command results in No executable found matching command "dotnet-ef"


Solution

  • You can generate the SQL script to revert a migration using the Script-Migration or dotnet ef migrations script command.

    dotnet ef migrations script TheAppliedMigration TheMigrationBeforeIt -o revert.sql