Net Core: Reset EF Migrations to a clean State
Net Core: Reset EF Migrations to a clean State:
Doc:
- https://stackoverflow.com/questions/43687433/update-database-command-is-not-working-in-asp-net-core-entity-framework-6-beca
- https://weblog.west-wind.com/posts/2016/jan/13/resetting-entity-framework-migrations-to-a-clean-slate
Migrating Production Database with EF Code First: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)You've now essentially reset the schema to the latest version.
- Remove comments in the Initial method
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.
- https://stackoverflow.com/questions/29746937/is-it-ok-to-update-a-production-database-with-ef-migrations
- https://cpratt.co/migrating-production-database-with-entity-framework-code-first/
Doc:
Comments
Post a Comment