EF Core Migrations: Remove Migrations and Re-Sync Database

c# entity-framework entity-framework-core

Question

I am using EF Core and have built a database with using the code first approach.

I'm not sure where, but my migrations are out of sync, however my latest build code does match whats in the database. How can I can I delete all migrations, and sync my database to my EF core with out losing any data?

1
1
3/14/2020 2:07:57 AM

Popular Answer

As I understood, your migrations are not in sync with your database, because someone was changing the database directly.

You can regenerate your models, DB context and entity configurations from an existing database. Investigate Entity Framework Database First .Net Core

If that is the case, you can delete all the migrations (whole Migration folder), entity configurations (if you used Fluent API) and DB context.

You will not have your migrations as you had, from the initial creation of the database anymore. Models, entity configurations and DB context will be created/scaffolded from an existing database.

Useful links: here and here.

2
3/14/2020 3:32:45 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow