I am using Entity Framework to redo our ancient internal auth system and have ran into an issue where running
dotnet ef database update
is running the wrong migrations...
When I run with the --verbose
option, I get this output:
info: Microsoft.EntityFrameworkCore.Migrations[20402]
Applying migration '20250130171432_InitialCreate'.
This was the old migration before I had to modify our User
role to have some different fields. I then ran dotnet ef database drop
and deleted the old migrations.
After I finished doing what I needed to do on the existing objects I ran
dotnet ef database update --verbose
and still got that it was trying to apply 20250130171432_InitialCreate
. That migration doesn't even exist on disk anymore so I am confused. To be safe I also ran dotnet clean
& dotnet build
, even so I am still not able to run the new migration which is the only one on disk.
This seems to have been an IDE specific issue (JetBrains Rider). It seems that the old migrations still existed to rider but not on disk. So when building my project they were being included into the bin/debug
folder.
I was able to fix this by invalidating my caches, and then resetting my IDE. I also had to run
dotnet ef database drop
# To clarify that I was going to delete all migrations
# Windows version
Remove-Item .\Migrations -Recurse
# Linux Version
rm -rf Migrations/
# Create new migration
dotnet ef migrations add Name_Of_New_Migration
# Update your db
dotnet ef database update
This worked for me, I am still confused on why Rider included non-existent files into a build.