Floxy
Floxy

Reputation: 137

EF core DataBase Update

Guys we moved Framework 7 to EF core 2.0 .So right now we have a Small problem.

when We use Entity Framework 7 its mostly easy to update client Database without any doubt.(update -database)

but in EF core there is a problem the reason is for every changes we have to add add-migration so in that case we have now 100 migration history.

example :(20180313063924_NewVersion,14689013063934_NewVersion etc)

so when we update client database we have to keep that 100 migration history But i think this is not the good way when its come to production level

is there anyway to resolve this problem.it would be helpful so much thank you!!

Upvotes: 0

Views: 353

Answers (1)

ChW
ChW

Reputation: 3348

Well, it is exactly the way like EF and EFCore are working.

Every migration represents the needed modification on DbContext/Database to be valid with model's changes. So if you have changes, they will be represented by a migration.

One - in my opinion - not very clean solution could be:

  1. delete current database
  2. delete whole Migrations directory (is valid too to delete all migration files and <yourContextName>Snapshot.cs file in Migrations directory)
  3. add new migration e.g. InitialCreate

The result will be only one migration that represents your current project's model/dbcontext state. The approach is only possible if the project is still in dev-phase without any deployments on any stages.

Please note, I don't recommend that solution/approach. In my opinion you should leave the migrations like they are.

For further information you should read following:

  1. The Model Snapshot In Entity Framework Core
  2. Migration in Entity Framework Core

Upvotes: 1

Related Questions