How to recover from deleting Migration History in ASP.NET core using Entity Framework Core

David Lane-Joynt 41 Reputation points

I have accidently deleted the EFMigrationsHistory table in my local setup by importing the entire database from the production site (backing it up and then restore it in local database). I cannot now update the database from a new migration.

I have tried manually updating the EFMigrationHistory table with the Migration identities from my Migrations folder in the Visual Studio solution explorer, but this does not work. The update-database EF command gives an error message that it is trying to create a table which already exists.

Do I have any alternative to deleting the local database and recreating it from the migrations in which case I will have to import the data from my production database. Not a very happy thought.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
626 questions
Microsoft Technologies based on the .NET software framework.
2,291 questions
A set of technologies in the .NET Framework for building web applications and XML web services.
3,757 questions
{count} votes

Accepted answer
  1. Jack J Jun 23,961 Reputation points Microsoft Vendor

    @David Lane-Joynt, Welcome to Microsoft Q&A, based on my test, I reproduced your problem.

    Please delete all existing migrations from the Migrations Folder.

    After deleting these migrations, I find that I could use Add-Migration and Update-DataBase command to update database successfully without the problem.

    Hope my advice could help you.

    Best Regards,


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.  

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful