❔ How to handle migration with column changes in Ef Core code first?
I need to change a table which is already in production.
Specifically I need to change a field which is currently an integer which represents a week number.
I now need to change it to a proper datatime.
Ideally I would like to do something like this:
1. Add a new column to the table - StartDate
2. Add some code to the migration Up file which runs through all the instances of that table and reads the StartWeek column and writes to the StartDate
3. Remove the StartWeek column
What is the best practice for handling this?
6 Replies
You can do exactly what you suggested. The generated migrations are editable, and for good reason.
There is no way to access the dbcontext from the migration from my understanding?
So adding code is not really an option, all I can add is SQL?
correct.
That is a bummer, as my SQL skills are way lower then C#
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.