I updated my data model by removing a column from a table to another, but I hava data in this column
To do that, I started by adding the new column in the new table and its done.
Now I want to migrate column data from the old table to the new one, I'm thinking to do it in the
Up(MigrationBuilder migrationBuilder) method but I don't know the right approach.
So, I'm asking if anyone knows from where I can start.
Thank you all!
Up() Method of the migration you can write custom SQL using the
migrationBuilder.Sql() function - this is generally the way that I would handle data being migrated from one column to another or in this case across tables.
Bear in mind of course that things are executed in an order, so you would need the sql to run between the column being added and the other being dropped.
Equally for safety sake and keeping things backwards compatible in the
Down() side of things you should also include the sql that does the reverse so that you can always roll back later
For example, we have table A and table B.
In my projects, I follow three-step procedure:
Down()part I add code to delete this column in table B.
Down()part I add code to transfer data from table B to table A.
Down()part I add code to create column to table A.