Skip to content

Instantly share code, notes, and snippets.

@jourdanrodrigues
Created May 19, 2020 17:57
Show Gist options
  • Save jourdanrodrigues/e60d43de76592b2dcdc9726a133ee97e to your computer and use it in GitHub Desktop.
Save jourdanrodrigues/e60d43de76592b2dcdc9726a133ee97e to your computer and use it in GitHub Desktop.
from django.db import migrations
def update_content_types(apps, schema_editor):
db_alias = schema_editor.connection.alias
ContentType = apps.get_model('contenttypes.ContentType')
ContentType.objects.using(db_alias).filter(app_label__in=['<old_app_1>', '<old_app_2>']).update(app_label='<remaining_app>')
class Migration(migrations.Migration):
dependencies = [
('<remaining_app>', '<file name of your latest migration>'),
]
operations = [
migrations.RunPython(code=update_content_types, reverse_code=migrations.RunPython.noop)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment