none
Regenerating Missing Code-First Migrations RRS feed

  • Question

  • When I originally created the database for my project, I started by manually creating certain tables and table columns. I have since moved to migrations, and now have a gap in my database creation. I'm worried that if I ever have to re-generate my database from my CF migrations I'll be left with a gap that I can't fill (everything that I added before I switched to migrations).

    Is there a way that I can generate a migration file that will generate all of the tables and columns required based on my models? If I can do that, I can just remove the parts that I don't already have and go from there.

    As an afterthought, how does it chose the order in which it should upgrade/downgrade the database? Is it the date in front of the migration name?


    Wasabi Fan

    Wednesday, January 22, 2014 3:26 AM

Answers

  • I figured it out. I cleared everything from my database, deleted all of my migrations (still in SC in case I need them) and created one migration for everything that I need. I would have preferred a more delicate solution, but this worked.


    Wasabi Fan

    • Marked as answer by Wasabi Fan Saturday, January 25, 2014 3:06 AM
    Saturday, January 25, 2014 3:06 AM

All replies

  • Hello,

    >>Is there a way that I can generate a migration file that will generate all of the tables and columns required based on my models?

    If I understand correctly, the “my models” should be your entities classes and the mapping classes.

    This is actually what Code First Migrations is used to do. The Code First Migrations is always based on these entities and their correspondent mapping classes.

    >> how does it chose the order in which it should upgrade/downgrade the database? Is it the date in front of the migration name?

    For upgrade/downgrade the database using Code First Migrations, we use command:

    Update-Database –TargetMigration: XXX

    The “XXX” is the class name in migrations folder.

    For details, please refer to link below:

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

    The data in front of the migration name shows the version, if the date is bigger, the migration version is newer.

    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.

    Thursday, January 23, 2014 3:06 AM
    Moderator
  • The problem is that running all of my migrations won't re-create everything. The first migration assumes that a few tables and columns exist, and I need a way to make a migration that would create everything from the ground up. Is there a way that I can do that?


    Wasabi Fan

    Thursday, January 23, 2014 3:12 AM
  • >> The problem is that running all of my migrations won't re-create everything.

    Do you mean that the database does not be changed after you run different migration versions?

    >> The first migration assumes that a few tables and columns exist, and I need a way to make a migration that would create everything from the ground up. Is there a way that I can do that?

    Backup the data in database, delete the existing database, and use the PMC command to create the database and migrant it again.


    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.

    Friday, January 24, 2014 9:38 AM
    Moderator
  • I figured it out. I cleared everything from my database, deleted all of my migrations (still in SC in case I need them) and created one migration for everything that I need. I would have preferred a more delicate solution, but this worked.


    Wasabi Fan

    • Marked as answer by Wasabi Fan Saturday, January 25, 2014 3:06 AM
    Saturday, January 25, 2014 3:06 AM