C
C#16mo ago
Ole

❔ 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
Pobiega
Pobiega16mo ago
You can do exactly what you suggested. The generated migrations are editable, and for good reason.
Ole
Ole16mo ago
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?
Pobiega
Pobiega16mo ago
correct.
Ole
Ole16mo ago
That is a bummer, as my SQL skills are way lower then C#
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Accord
Accord16mo ago
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.
Want results from more Discord servers?
Add your server
More Posts