Skip to content

Instantly share code, notes, and snippets.

@smcoll
smcoll / 0002_merge_tables.py
Created August 7, 2018 15:30
Django migration to merge one table's records into another similar table (both having UUID primary keys)
from django.db import migrations
def merge_foo_into_bar(apps, schema_editor):
""" For each FooCategory, create a corresponding BarCategory (with the new type)
and for each Foo, create a corresponding Bar.
The idea is that Foo and FooCategory would be dropped in a subsequent migration.
"""
Foo = apps.get_model('myapp', 'Foo')