mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
Fix exception in 0002 migration (#579)
This commit is contained in:
parent
f1d0dfcb8d
commit
a68bf903cf
1 changed files with 10 additions and 10 deletions
|
|
@ -1,7 +1,6 @@
|
|||
from logging import getLogger
|
||||
|
||||
from django.core.management.color import no_style
|
||||
from django.db import DatabaseError
|
||||
from django.db import migrations
|
||||
|
||||
logger = getLogger(__name__)
|
||||
|
|
@ -14,15 +13,16 @@ def _migrate_from_old_table(apps, schema_editor) -> None:
|
|||
"""
|
||||
connection = schema_editor.connection
|
||||
quoted_string = ', '.join([connection.ops.quote_name(item) for item in ['id', 'key', 'value']])
|
||||
try:
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute(
|
||||
f'INSERT INTO constance_constance ( {quoted_string} ) SELECT {quoted_string} FROM constance_config', # noqa: S608
|
||||
[],
|
||||
)
|
||||
cursor.execute('DROP TABLE constance_config', [])
|
||||
except DatabaseError:
|
||||
logger.exception('copy data from old constance table to a new one')
|
||||
old_table_name = 'constance_config'
|
||||
with connection.cursor() as cursor:
|
||||
if old_table_name not in connection.introspection.table_names():
|
||||
logger.info('Old table does not exist, skipping')
|
||||
return
|
||||
cursor.execute(
|
||||
f'INSERT INTO constance_constance ( {quoted_string} ) SELECT {quoted_string} FROM {old_table_name}', # noqa: S608
|
||||
[],
|
||||
)
|
||||
cursor.execute(f'DROP TABLE {old_table_name}', [])
|
||||
|
||||
Constance = apps.get_model('constance', 'Constance')
|
||||
sequence_sql = connection.ops.sequence_reset_sql(no_style(), [Constance])
|
||||
|
|
|
|||
Loading…
Reference in a new issue