c# - Entity Framework applying migration that no longer exists - Stack Overflow

admin2025-04-17  2

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.

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.

Share Improve this question edited Feb 6 at 19:37 Svyatoslav Danyliv 27.6k4 gold badges22 silver badges42 bronze badges asked Jan 30 at 18:21 Mr NeptuneMr Neptune 377 bronze badges 4
  • I highly doubt that it is possible for you but still worth asking - can you please provide a full minimal reproducible example? – Guru Stron Commented Jan 30 at 19:33
  • on disk means the files under Migrations folder? – Ivan Petrov Commented Jan 30 at 20:28
  • 2025-01-30 doesn't sound very old to me... – Jeremy Lakeman Commented Jan 31 at 0:42
  • Check the migrations folder with Windows Explorer. – mxmissile Commented Jan 31 at 14:41
Add a comment  | 

2 Answers 2

Reset to default 1

Please make sure that there is no migration 20250130171432_InitialCreate.cs in the /migrations folder.

You can also do a whole-app search by the name of the migration to make sure there are no secondary sources that might be looked at when getting migrations.

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.

转载请注明原文地址:http://anycun.com/QandA/1744898499a89186.html