Home > Back-end >  Deleted local database tables using SSMS and can't recreate it with ASP.NET Entitiy Framework
Deleted local database tables using SSMS and can't recreate it with ASP.NET Entitiy Framework

Time:11-18

I've been a bit gung ho and deleted my database tables using SQL Server Management Studio (SSMS) and deleted all the migrations manually too.

The database is local and was for testing purposes only. How can I create the tables again with Entity Framework?

If it involves a lot of work am I better starting a fresh ASP.NET app and copying across my code?

CodePudding user response:

If you want to start with one fresh migration because you didn't deploy your app yet, you can:

  1. Remove the Migrations directory including its snapshot and migration files.
  2. Create a new migration: dotnet ef migrations add Initial
  3. Update your database: dotnet ef database update

This will generate one migration and initalize the database according to the current state of your entities.


If you only deleted your database but still have your migrations, getting a fresh one is as simple as:

dotnet ef database update
  • Related