Extend migration to update original content type for ConfigRevision

This commit is contained in:
Jeremy Stretch 2023-11-27 15:49:32 -05:00
parent b567dfd09e
commit e111af4764
2 changed files with 16 additions and 1 deletions

View File

@ -25,7 +25,7 @@ class Migration(migrations.Migration):
}, },
), ),
], ],
# Table has been renamed from extras_configrevision # Table will be renamed from extras_configrevision in extras/0101_move_configrevision
database_operations=[], database_operations=[],
), ),
] ]

View File

@ -1,6 +1,17 @@
from django.db import migrations from django.db import migrations
def update_content_type(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
# Delete the new ContentType effected by the introduction of core.ConfigRevision
ContentType.objects.filter(app_label='core', model='configrevision').delete()
# Update the app label of the original ContentType for extras.ConfigRevision to ensure any foreign key
# references are preserved
ContentType.objects.filter(app_label='extras', model='configrevision').update(app_label='core')
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
@ -21,4 +32,8 @@ class Migration(migrations.Migration):
), ),
], ],
), ),
migrations.RunPython(
code=update_content_type,
reverse_code=migrations.RunPython.noop
),
] ]