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 logging import getLogger
|
||||||
|
|
||||||
from django.core.management.color import no_style
|
from django.core.management.color import no_style
|
||||||
from django.db import DatabaseError
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
@ -14,15 +13,16 @@ def _migrate_from_old_table(apps, schema_editor) -> None:
|
||||||
"""
|
"""
|
||||||
connection = schema_editor.connection
|
connection = schema_editor.connection
|
||||||
quoted_string = ', '.join([connection.ops.quote_name(item) for item in ['id', 'key', 'value']])
|
quoted_string = ', '.join([connection.ops.quote_name(item) for item in ['id', 'key', 'value']])
|
||||||
try:
|
old_table_name = 'constance_config'
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
cursor.execute(
|
if old_table_name not in connection.introspection.table_names():
|
||||||
f'INSERT INTO constance_constance ( {quoted_string} ) SELECT {quoted_string} FROM constance_config', # noqa: S608
|
logger.info('Old table does not exist, skipping')
|
||||||
[],
|
return
|
||||||
)
|
cursor.execute(
|
||||||
cursor.execute('DROP TABLE constance_config', [])
|
f'INSERT INTO constance_constance ( {quoted_string} ) SELECT {quoted_string} FROM {old_table_name}', # noqa: S608
|
||||||
except DatabaseError:
|
[],
|
||||||
logger.exception('copy data from old constance table to a new one')
|
)
|
||||||
|
cursor.execute(f'DROP TABLE {old_table_name}', [])
|
||||||
|
|
||||||
Constance = apps.get_model('constance', 'Constance')
|
Constance = apps.get_model('constance', 'Constance')
|
||||||
sequence_sql = connection.ops.sequence_reset_sql(no_style(), [Constance])
|
sequence_sql = connection.ops.sequence_reset_sql(no_style(), [Constance])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue