How to remove a migration manually in EF core 6 (I don't have the Migrations/ts_migrationfile.cs)?

Viewed 366

I'm having trouble with a migration that seems to have been wrongly deleted by EF core. It says I have to manually delete some file, since the migration file was not found, but I can't find a guide on how I'm supposed to delete that.

  1. I had my initial create migration
  2. I added a new one for creating a couple more columns in a table
  3. I didn't realize that mi project was set to pgsql instead of sqlite
  4. I deleted the migration (never applied database update)
  5. Ef core delete command deleted the migration files on ./Data/Migrations
  6. I set sqlite
  7. I added a new migration
  8. The new migration was on pgsql again
  9. Delete migration tries to delete the (step 2) migration instead of (step 6) migration and fails.

It says No file named '20220308_Migration2.cs' was found. You must manually remove the migration class 'Migration2', hence the question.

My commands for adding and removing and listing the migrations were the followings:

dotnet ef migrations add name -c MyContext -p .\Project.Db\Project.Db.csproj -o .Project.Db\Data\Migrations -s .\Project.Server\Project.Server.csproj

dotnet ef migrations delete name -c MyContext -p .\Project.Db\Project.Db.csproj -s .\Project.Server\Project.Server.csproj

dotnet ef migrations delete name -c MyContext -p .\Project.Db\Project.Db.csproj -s .\Project.Server\Project.Server.csproj

After all done, if I execute the list command, output shows:

Migration1 (pending)
Migration2 (pending)

Where Migration1 is the initial create and Migration2 is the migration applied on step2.

The files I have on Data/Migrations folder are the ones corresponding to Migration1 and Migration3 (step 6)

Another questions.

Where does the list command data comes from? is there a secret database or a hidden caché folder?

If I just delete the Data/Migrations folder, will I be able to start over with the migrations?

Thanks

1 Answers

My problem was on communication between projects. I failed to mention before that I have my solution splitted between projects (as you can see by the commands), and happens that those projects are linked to each other by hard links (Microsoft's mklink -h) to de .dll of the compiled lower layer project.

What happened was that somehow the hardlink between the DB project and the Server project failed, so the Server project was not aware about the changes on the Db project, and it could only see the DB project as it was at the moments the hard link failed.

I finally deleted the reference and added it again. As soon as I did that, the project recognized the real state of the migrations and everything went smoothly.

So (answering my questions), the message was telling me to delete the migration file in ./Data/Migrations. The file was deleted, but the Server project could not see that.

The "cache" was actually the broken hard-link that referenced an old version of the DB project. The list command scans the folder -/Data/Migrations and compares with the database.

Related