diff --git a/netbox/core/migrations/0009_configrevision.py b/netbox/core/migrations/0009_configrevision.py index 46b3764b5..e7f817a16 100644 --- a/netbox/core/migrations/0009_configrevision.py +++ b/netbox/core/migrations/0009_configrevision.py @@ -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=[], ), ] diff --git a/netbox/extras/migrations/0101_move_configrevision.py b/netbox/extras/migrations/0101_move_configrevision.py index e07d6ed9d..730e7a096 100644 --- a/netbox/extras/migrations/0101_move_configrevision.py +++ b/netbox/extras/migrations/0101_move_configrevision.py @@ -1,6 +1,17 @@ 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): dependencies = [ @@ -21,4 +32,8 @@ class Migration(migrations.Migration): ), ], ), + migrations.RunPython( + code=update_content_type, + reverse_code=migrations.RunPython.noop + ), ]