Skip to content

Instantly share code, notes, and snippets.

@BenAtWide
Created April 10, 2019 13:42
Show Gist options
  • Save BenAtWide/3485cae5ee177532c4e5073898007f58 to your computer and use it in GitHub Desktop.
Save BenAtWide/3485cae5ee177532c4e5073898007f58 to your computer and use it in GitHub Desktop.
from django.db import migrations
def combine_names(apps, schema_editor):
# We can't import the Person model directly as it may be a newer
# version than this migration expects. We use the historical version.
Person = apps.get_model('yourappname', 'Person')
for person in Person.objects.all():
person.name = '%s %s' % (person.first_name, person.last_name)
person.save()
class Migration(migrations.Migration):
dependencies = [
('yourappname', '0001_initial'),
]
operations = [
migrations.RunPython(combine_names),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment