Question

The project I am working on is using Entity Framework 4.3 and data migrations to keep the schema up to date. Over the course of the project the migrations folder has grown and now has over 600 files. This is huge. We now have a binary which is over 12MB due to all the migration meta data.

I would like to collapse all these in to one migration and start again. My concerns are:

  1. Is this possible or will it cause problems with the migration history if I remove migrations?
  2. Are there any guides around describing how to do this?
Was it helpful?

Solution

First: I recommend that you keep your migrations in a separate assembly so they don't have to be published with the application. It could be a simple console app that applies the migrations or a winforms GUI that generates scripts. But there's no reason for it to be deployed with the app imo.

Second: Understanding that you'd be giving up the ability to roll back to previous versions, you could just exclude-from-project all of your prior migrations then generate a new one which should then be able to create a database reflecting your current model. That would serve as your new starting point. Remember that EF doesn't always generate code to do everything you want in a migration, so you might have some hand-written migration code in other migrations you'd need to pull in.

OTHER TIPS

Not sure past versions, but if you are here looking for the same solution for EF Core. You should be able to just delete the ModelSnapshot and re-run your migration to create a clean sheet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top