RevertMigration: commit both migrations, .NET 10, tests - #2265
Open
vladimir-pecanac-main wants to merge 1 commit into
Open
vladimir-pecanac-main wants to merge 1 commit into
vladimir-pecanac-main wants to merge 1 commit into
Conversation
The folder held the model with HasDoors but only the Init migration, so a clean clone crashed on the first insert with "table Hangars has no column named HasDoors". Init is regenerated from the start state and Hangar_HasDoors is added, both keeping the migration IDs the article prints. The regenerated Init also matches the nullable model columns. Retarget to net10.0 with EF Core 10.0.12 and add an xunit test project that applies, reverts and fully reverts the migrations against a temporary SQLite file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sample for the article "How to Revert a Migration in EF Core" (https://code-maze.com/efcore-how-to-revert-a-migration/).
Fixes the sample, which did not run. Models/Hangar.cs and Program.cs use HasDoors, but the only committed migration was Init, which has no HasDoors column, so a clean clone applied Init and then crashed on the first SaveChanges() with "SQLite Error 1: 'table Hangars has no column named HasDoors'".
Changes, all inside dotnet-efcore/RevertMigration:
Packages, re-queried on NuGet on 2026-10-04: Microsoft.EntityFrameworkCore.Sqlite 10.0.12, Microsoft.EntityFrameworkCore.Design 10.0.12, xunit 2.9.3, xunit.runner.visualstudio 4.0.0, Microsoft.NET.Test.Sdk 18.10.1, coverlet.collector 10.1.0.
Local: dotnet build -c Release 0 warnings 0 errors; dotnet test 4 passed; dotnet list package --vulnerable --include-transitive clean; dotnet ef database update applies both migrations and dotnet run prints both "Just created" lines (SDK 10.0.302, runtime 10.0.10, dotnet-ef 10.0.12).
Note for anyone who ran an older version: the sample keeps its database at LocalApplicationData/airport.db, outside the project folder, so a stale airport.db from an earlier run survives a clean clone. Delete it before running.