locked
Multiple CodeFirst Migration RRS feed

  • Question

  • On my local machine, from Visual Studio, I did a database migration a few times (because the first wasn’t what I wanted) on table myTable. 

    201610202156479_myTable_migration_1.cs
    201610202156479_myTable_migration_2.cs
    201610202156479_myTable_migration_3.cs
    201610202156479_myTable_migration_4.cs

    201610202156479_myTable_migration_1.cs: added 4 new int columns
    201610202156479_myTable_migration_2.cs: in Visual Studio, changed the 4 int columns to be nullable, ie

    public int? intMyNewCol1 { get; set; }

    201610202156479_myTable_migration_3.cs: created foreign key from the 4 new int columns to another table
    201610202156479_myTable_migration_4.cs: removed the 4 new int columns, and added 4 new varchar columns

    I want the last migration (4 new varchar columns) to be the one migrated to Production system.

    When checking in the database migration to TFS, do I need to check in all 4 migrations above ?
    Do we need to do all 4 migrations to the Production database ?

    THank you.

    Tuesday, October 25, 2016 7:48 PM

All replies

  • Hi aujong,

    If you wan to migrate to production system. I would suggest that you could refer Jon Smith's article, which you need to comparing EF/SQL databases.

    https://www.simple-talk.com/dotnet/net-framework/deploying-an-entity-framework-database-into-production/

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 26, 2016 3:03 AM
  • Thank you Cole.
    The article uses DbUp.

    If I don't use DbUp, and only use EF Code First Migration, what do I need to do in the above situation ?
    Do I need to deploy all 4 migrations above ?

    Thank you

    Wednesday, October 26, 2016 2:15 PM
  • Hi aujong,

    According to your description, I assume that you want to Migrate to a Specific Version, if it is the case. please use:

    update-Database –TargetMigration: myTable_migration_4 

    For more information, please refer to:

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

    If I misunderstand your issue, please feel free let me know.

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Thursday, October 27, 2016 1:08 AM