0

I am getting inner exception Invalid object name {entity name} from SaveChanges using Migrations and EF Core in a console program. The migrations were created and the database updated. The program ran once but I wanted to re-run it. I deleted the table. Probably that was the mistake. I assume the current exception is because the table was deleted.

I cannot get the table re-created. I tried removing the migration and I tried reverting and doing other things but everything I tried did not work. There might be something in the code I can use to get the table re-created but I do not know what.

I see answers in c# - Entity Framework 4.3 doesn't create database - Stack Overflow that might work but I am not sure.

For the future I will do something like delete all records instead of deleting the table but I am not asking about that.

I am using the dotnet cli commands instead of Package Manager Console. I can use either but responses using dotnet cli commands is prefered.

Sam Hobbs
  • 2,594
  • 3
  • 21
  • 32

1 Answers1

0

I solved the problem by deleting everything in the Migrations folder for the project. I then deleted the database using SQL Server Object Explorer. I was then able to repeat the original migrations create and database update.

There should be an official supported solution but until there is one (provided here) this workaround worked for me.

Sam Hobbs
  • 2,594
  • 3
  • 21
  • 32