Skip to content

Commit

Permalink
[Fixes #223] Migration error 0005_fixup_dynamic_shema_table_names (#224)
Browse files Browse the repository at this point in the history
* [Fixes #223] Migration error 0005_fixup_dynamic_shema_table_names
  • Loading branch information
mattiagiupponi authored Feb 14, 2024
1 parent e4df133 commit 853958c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions importer/migrations/0005_fixup_dynamic_shema_table_names.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
from django.db import migrations
import logging
from django.db import ProgrammingError
from django.db import connections

logger = logging.getLogger(__name__)


def fixup_table_name(apps, schema_editor):
try:
schema = apps.get_model("dynamic_models", "ModelSchema")
for val in schema.objects.all():
if val.name != val.db_table_name:
val.db_table_name = val.name
val.save()
except ProgrammingError as e:
"""
The dynamic model should exists to apply the above migration.
The dynamic model should exists to apply the migration.
In case it does not exists we can skip it
"""
if 'relation "dynamic_models_modelschema" does not exist' in e.args[0]:
logging.debug("Dynamic model does not exists yet, skipping")
return
raise e
if 'dynamic_models_modelschema' in schema_editor.connection.introspection.table_names():
schema = apps.get_model("dynamic_models", "ModelSchema")
for val in schema.objects.all():
if val.name != val.db_table_name:
val.db_table_name = val.name
val.save()
except Exception as e:
raise e

Expand Down

0 comments on commit 853958c

Please sign in to comment.