Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #223] Migration error 0005_fixup_dynamic_shema_table_names #224

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading