0

My project has many migrations. To be precise, there are 35. Now that we're going for version 1.0 I want to "sum" these 35 migrations into a single migration for ease of control.
How can I do that?
How can I generate a aggregate of all these migrations as if I have never created a previous migration?

Details:

  • EF 6
  • Using Code First
  • Automatic Migrations: False

Deleting the previous migrations and trying to "Add-Migration" does not work... neither does rolling back the database to target migration 0... Is there a flag such as "Ignore Previous Migrations"?

Leonardo
  • 10,737
  • 10
  • 62
  • 155
  • You can call Update-Database -Script -–TargetMigration:XXX which will create a SQL script of the migrations from the DB's current state to migration XXX. Is that what you need? – Matt Jul 16 '15 at 13:09
  • 1
    I'd call this "collapsing" migrations. Going from 35 to 1. Here's a possible dupe, which I think is correct http://stackoverflow.com/questions/22789065/what-is-the-best-way-to-collapse-all-existing-enityt-framework-migrations I think, in addition to deleting all code migrations, you may have to remove the history from the database migration table as well. But I'm not sure; EF might take care of that for you. –  Jul 16 '15 at 13:11
  • @Matt, actually no, i need a migration, not a script... I need the class with the create tables and etc to later run the update-database... – Leonardo Jul 16 '15 at 13:12
  • I guess you could write your own migration generator. http://romiller.com/2012/11/30/code-first-migrations-customizing-scaffolded-code/ – Matt Jul 16 '15 at 13:17
  • Are you deleting the _MigrationHistory records as well? I've done this several times using this technique. http://cpratt.co/migrating-production-database-with-entity-framework-code-first/#at_pco=smlwn-1.0&at_si=54ad5c7b61c48943&at_ab=per-12&at_pos=0&at_tot=1 – Steve Greene Jul 16 '15 at 13:19

1 Answers1

1
  1. Rollback your database (Update-Database -TargetMigration 0)
  2. Delete all migrations
  3. Recompile everything (very important!!! Spent about 15min on "explicit migration pending...")
  4. Add new migration!
Leonardo
  • 10,737
  • 10
  • 62
  • 155