Net Core: Reset EF Migrations to a clean State

Net Core: Reset EF Migrations to a clean State:

Removing and Resetting MigrationsThe 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.
In summary, the steps to do this are:
  • 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
You've now essentially reset the schema to the latest version.
Again if you had custom code in your old migrations that added custom constraints or modified data alongside of the generated Migration code you may have to add this code back in the initial migration generated.
Migrating Production Database with EF Code First:



Doc:


Comments

Popular posts from this blog

Use GnuPG Tools or C# Code for PGP Encryption and Signature

Errors in Net Core Add-Migration

Confusing Concepts about SFTP: SSH2 vs OpenSSH