Search code examples
sql-servervisual-studio-2015database-migrationcode-first

Missing Migration data in SQL when trying to add-migration


I have made use of a backup database and have added a new table using Code First. Now when I tried using add-migration, I got this error:

Unable to generate an explicit migration because the following explicit migrations are pending

Suggesting that the Migrations in the project do not match which are in the DB, which when I looked, there are NO migrations in the __migration table any more ?

As these tables exist in the DB, how do I get all of these migrations inserted into my SQL DB ? Is there a way I can get them all added, so that the projects migrations and the SQL DB migrations will match, so that I can continue adding/editing tables ?

Thanks in advance for any help.


Solution

  • So I found something that did help! It unfortunately meant that I lost all of my migration files, but thats not the end of the world.

    The below is reference from this site: Click here

    • Remove the _MigrationHistory table from the Database
    • Remove the individual migration files in your project's Migrations folder
    • Enable-Migrations in Package Manager Console
    • Add-migration Initial in PMC
    • Comment out the code inside of the Up method in the Initial Migration
    • Update-database in PMC (does nothing but creates Migration Entry)
    • Remove comments in the Initial method

    I hope this helps someone else as well.