1

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?

Tom Crosman
  • 1,137
  • 1
  • 12
  • 37
  • I think what you are trying to do is reverse a migration, here it talks about the command used to update migration but restoring database: https://www.learnentityframeworkcore.com/migrations – Alejandro H Mar 14 '20 at 02:22
  • No not that. Someone manually altered the table. And so I can’t sync, even tho my changes are the same as what changed in the database. – Tom Crosman Mar 14 '20 at 02:28

1 Answers1

2

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.

Vladimir
  • 1,624
  • 7
  • 25
  • 56