One option is to split the task into 3 migrations:
- schema migration: adding
release_year
field - data migration: filling
release_year
field fromrelease_date
field - schema migration: remove
release_date
field and renamerelease_year
torelease_date
Schema migrations would be caught by south automagically (using schemamigration --auto
), but you need to write a data migration manually, here's how your forwards()
method should look like:
def forwards(self, orm):
for source in orm.Source.objects.all():
source.release_year = source.release_date.year
source.save()
Hope that helps.