Magnus Lundberg
Magnus Lundberg

Reputation: 803

Alter field with data migration in Django

I have a Django application with a database with data.

All data have a timestamp when it was published on the form "season year". For example: "Spring 2017" or "Summer 2015"

I would like to change that field to a date and migrate all data to a default value for each season (Spring 2016 should be replaced with 2017-04-01, Winter 2013 with 2013-01-01 and so on)

Is there any way to do this with the standard migration?

Upvotes: 2

Views: 1110

Answers (1)

iankit
iankit

Reputation: 9382

  • Step 1 : Create a new column with new type, nullable
  • Step 2 : With every new data created start filling in this column as well
  • Step 3 : Write a script to migrate old data
  • Step 4 : Remove nullable
  • Step 5 : Start reading from this column for all use cases
  • Step 6 : If required, dispose of old column at a later date

Upvotes: 1

Related Questions