



Update-database in PMC (does nothing but creates Migration Entry).Comment out the code inside of the Up method in the Initial Migration.Enable-Migrations in Package Manager Console.

Remove the individual migration files in your project's Migrations folder.Remove the _MigrationHistory table from the Database.The idea of this process is basically this: The database and the EF schema are up to date and just the way you want it, so we are going to remove the existing migrations and create a new initial migration. But your mileage may vary, so whatever you do be safe about the data and code you already have and do the backup. You may have to add these additional manual steps to the initial migration that gets created…Īll that said I've had to do this sort of reset on a large project with a couple of hundred tables and it worked without a problem. This is especially true if you have custom code in your migrations that perform additional tasks to update the database. And you don't want to be stuck in that place without a backup. While the EF code generator is pretty good at matching the EF schema and what's in your database, in some cases it doesn't work. If you go the route of resetting your migrations, make sure you back up your code and make known good backups of your database, just in case the schema reversion doesn't do what you expect. There's no built-in way to do this, so you have to perform a number of manual steps and that's what this post is about. That might mean rolling back to the last known good migration.Īs you might expect, resetting migrations is not as obvious as it could be – it's not use case that Entity Framework expects you to work with. Usually this isn't a problem as databases tend to be vital in order for anything to work so they are very likely to be up date, but if not you'll have to find that consistent state so that your EF schema and the database are in sync. To be clear this works only if all of your databases are up to date in the first place or at least in some known consistent state. I've found in most cases it's simply easier to blow away the migrations and start with a clean slate from the current schema. There are a number of hacks you can try to fix bonked migrations, but to be honest more often than not those simply don't work. Usually this happens after a large number of migrations have been applied and I get stuck to where I can't update a database with new migrations or roll back. Not sure if this is a common occurrence, but I've had a number of occasions where Entity Framework migrations have left the state of migrations in an unusable state.
