none
How to Clear Code First Migration History? RRS feed

  • Question

  • Hi Everyone,

    I'm using code first for my new project, and the project is still being developed.

    Sometimes my database cannot be updated properly, so I just delete my database, and use "update-database -f" to generate a new database.

    I thought the new generated database was synchronized with my code (code first), But it wasn't.

    use -verbose I can see there were a lot of migrations in the command being executed.

    Where does the project store the history?

    Can I delete them all, So I can just use my current code to generate an initial version database which is synchronized with my current code.


    Silverlight is the best tech for enterprise programming. Of course html5+js+css3 can do it too, but only takes 5-10 more times effort to do it.

    Monday, February 25, 2013 12:59 AM

Answers

  • Automatic migrations don't output the migration files and will just apply changes to the database directly. Personally I avoid them as there's not real control over what has been applied and it's not easy to back out a migration for example. My understanding is that when automatic updates run against a database they should apply all changes they can find. There is a system table on the database called migration history that helps with this.
    • Marked as answer by SolenovexMVP Wednesday, February 27, 2013 5:58 AM
    Tuesday, February 26, 2013 10:23 AM

All replies

  • There's a folder created in your project called Migrations. This should contain a class for each migration you have created. You can delete these files if they are no longer needed.
    Monday, February 25, 2013 12:39 PM
  • I can see this folder, this folder contains the migration I've created.

    I notice that there are a lot of automatic migrations being generated by using command "update-database", where did ef store these automatic-migrations, Or Ef just didn't store automatic-migrations?


    Silverlight is the best tech for enterprise programming. Of course html5+js+css3 can do it too, but only takes 5-10 more times effort to do it.

    Tuesday, February 26, 2013 12:12 AM
  • Automatic migrations don't output the migration files and will just apply changes to the database directly. Personally I avoid them as there's not real control over what has been applied and it's not easy to back out a migration for example. My understanding is that when automatic updates run against a database they should apply all changes they can find. There is a system table on the database called migration history that helps with this.
    • Marked as answer by SolenovexMVP Wednesday, February 27, 2013 5:58 AM
    Tuesday, February 26, 2013 10:23 AM