0

When I make a new migration (Add-Migration Example) , and then I try to get all the migrations (Get-Migration) I find that the "applied" field is "True" without even using (Update-Database),furthermore when I try to revert all migrations back (Update-Database 0) , it tells me it has succeeded , and when I check that using Sql Server Object Explorer , I find that it really succeeded , but again using(Get-Migration) I find that again "applied" field is "True" ,and to make everything even worse , when I type (Remove-Migration) it tells me that the last migration is applied and you have to revert it to be able to remove it ,and I find that the migrations has been applied to the database again ,any idea what could cause this problem? (Sorry if you find my English is bad, it's not my primary language :) )

I did Try to remove the migrations and the database manually my self but it didn't result in anything , the problem remains.

1 Answer 1

0

Get-migration actually checks the "_efmigrationshistory" table. If a migration has been updated to database. The migration file name will be recorded in this "_efmigrationshistory" table.

enter image description here

enter image description here

You probably has updated the same name migration file before. So the name has been recorded. And when you check by Get-migration, it detected the same name and returned as "applied:true".

4
  • after some time messing with the database , i have discovered that the Get-Migration is the one that has the issue , if i tried to use it ,it doesn't just get me info about migrations i have , it also functions as Update-Database and sends to the database the Sql queries to make database and adding constrains etc , do you have any explanation for this weird behaviour Commented Dec 6, 2023 at 19:28
  • @elshaterhassan No I never see that happen. You could try reinstall the package or in new projects to see if it is normal.
    – Qiang Fu
    Commented Dec 7, 2023 at 9:18
  • 1
    The package and the database works fine in a new project! Thanks for your help. Commented Dec 8, 2023 at 4:35
  • 1
    i have updated from DotNet 7 to DotNet 8 , updating all packages to newest version , and creating a new project with copying old files from old project to the new one ( considering which to copy to not make any errors) . and now everything works properly, Commented Dec 8, 2023 at 7:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.