In your project, go to the package manager windows and:
- Enable Migration:
Enable-Migrations
- Create Migration:
Add-Migration Initial
- Create update / downgrade script:
Update-Database
In this case, you add a new table ( Color
) and two new columns.
You have a reason, if you run your site, FavoriteColor
will be deleted, including its data.
What can you do:
In the package manager console, when you run the Add-Migration Initial
, which will create a new script (C # file). As you can see in this file, one column is deleted, 2 and 1 tables are added.
Make sure the table is created before the columns, fills it with data, creates 2 columns with existing data based on the old column, and then deletes the column.
Another way (perhaps better) to do this in several migration scenarios, you can also use the Seed()
method to populate the data.
source share