none
How to restart/merge migration? RRS feed

  • Question

  • I'm using Entity framework code first and I have almost 10 migrations now. I found a design issue and some of the DBMigrations are not what I expected and I want to re-generated the database.

    1. How to discard all these existed migrations and regenerate the tables on development database? (delete all the cs files under Migrations folder and delete the database? What if I want to keep the first xxxxxx_InitialCreate.cs and restart from there?)
    2. What if the database already published to production database server? What's the best way to sync the development database/migrations and production database/migrations?
    • Moved by Caillen Tuesday, January 21, 2014 7:15 AM EF question.
    Monday, January 20, 2014 9:57 AM

Answers

  • Hello kxwang,

    >>How to discard all these existed migrations and regenerate the tables on development database? (delete all the cs files under Migrations folder and delete the database? What if I want to keep the first xxxxxx_InitialCreate.cs and restart from there?)

    We do not need to delete the database and since you want to keep the first xxxxxx_InitialCreate.cs and restart from there, we just downgrade the database to the initial version using command like below:

    Update-Database –TargetMigration: xxxxxx_InitialCreate

    For details, please refer to link below and search for “Migrate to a Specific Version (Including Downgrade)” section.

    http://msdn.microsoft.com/en-us/data/jj591621.aspx

    >>What if the database already published to production database server? What's the best way to sync the development database/migrations and production database/migrations?

    I do not a database expert, so in my opinion it should be simple: we need to publish it again and deploy it to server and since the database is already published to production database server, when we want sync it, first of all, please remember to backup the data.

    There are no best practices for it, however there are some deployment considerations regarding it:

    http://msdn.microsoft.com/en-us/magazine/hh126815.aspx(Deployment Considerations section)

    http://stackoverflow.com/questions/6490662/sync-development-sql-2008-with-production-database-sql-azure-and-want-to-kee

    For the second issue, I suggest you posting it to SqlServer forum:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver

    There are database experts who will help you better.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, January 21, 2014 8:25 AM
    Moderator

All replies

  • Hi kxwang,

    I'm moving your question to ADO.NET Entity Framework and LINQ to Entities forum where you could get more help.

    Thanks for your understanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 21, 2014 7:16 AM
  • Hello kxwang,

    >>How to discard all these existed migrations and regenerate the tables on development database? (delete all the cs files under Migrations folder and delete the database? What if I want to keep the first xxxxxx_InitialCreate.cs and restart from there?)

    We do not need to delete the database and since you want to keep the first xxxxxx_InitialCreate.cs and restart from there, we just downgrade the database to the initial version using command like below:

    Update-Database –TargetMigration: xxxxxx_InitialCreate

    For details, please refer to link below and search for “Migrate to a Specific Version (Including Downgrade)” section.

    http://msdn.microsoft.com/en-us/data/jj591621.aspx

    >>What if the database already published to production database server? What's the best way to sync the development database/migrations and production database/migrations?

    I do not a database expert, so in my opinion it should be simple: we need to publish it again and deploy it to server and since the database is already published to production database server, when we want sync it, first of all, please remember to backup the data.

    There are no best practices for it, however there are some deployment considerations regarding it:

    http://msdn.microsoft.com/en-us/magazine/hh126815.aspx(Deployment Considerations section)

    http://stackoverflow.com/questions/6490662/sync-development-sql-2008-with-production-database-sql-azure-and-want-to-kee

    For the second issue, I suggest you posting it to SqlServer forum:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=sqlserver

    There are database experts who will help you better.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, January 21, 2014 8:25 AM
    Moderator