问题
We are using Entity Framework code first migration technique for a while now. Everything works good however our Migrations folder has been growing big with numerous migration files because of changes we are making on entity schema. I was curious, is there a way we can update just one or specific number of files whenever there is change in entity so that our Migrations folder would look less messy. Also, i don't want to drop the table and recreate it since i will be loosing all the saved data.
回答1:
You could simply merge all of your migrations into a new file (if you aren't concerned with keeping every migration).
To do so, simply delete every migration currently in the folder, and rerun the enable-migrations command and then the add-migration command like so.
Enable-Migrations
add-migration InitialCreate
回答2:
You can try to use database initializer called MigrateDatabaseToLatestVersion. That automatically updates the database schema, when your model changes without losing any existing data or other database objects.
Database.SetInitializer(
new MigrateDatabaseToLatestVersion<YourDbContext,
DataLayer.Migrations.Configuration>());
来源:https://stackoverflow.com/questions/35872522/entity-framework-code-first-migration