From e111af4764b8519a9b1a410f1e08c6bfb9c0631d Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 27 Nov 2023 15:49:32 -0500 Subject: [PATCH] Extend migration to update original content type for ConfigRevision --- netbox/core/migrations/0009_configrevision.py | 2 +- .../extras/migrations/0101_move_configrevision.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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 + ), ]