mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
parent
bc9707d618
commit
d03bea804f
1 changed files with 11 additions and 5 deletions
|
|
@ -1,5 +1,10 @@
|
|||
from logging import getLogger
|
||||
|
||||
from django.core.management.color import no_style
|
||||
from django.db import migrations, connection, DatabaseError
|
||||
from django.db import migrations, DatabaseError
|
||||
|
||||
|
||||
logger = getLogger(__name__)
|
||||
|
||||
|
||||
def _migrate_from_old_table(apps, schema_editor) -> None:
|
||||
|
|
@ -7,13 +12,14 @@ def _migrate_from_old_table(apps, schema_editor) -> None:
|
|||
Copies values from old table.
|
||||
On new installations just ignore error that table does not exist.
|
||||
"""
|
||||
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('INSERT INTO constance_constance ( id, key, value ) SELECT id, key, value FROM constance_config', [])
|
||||
cursor.execute(f'INSERT INTO constance_constance ( {quoted_string} ) SELECT {quoted_string} FROM constance_config', [])
|
||||
cursor.execute('DROP TABLE constance_config', [])
|
||||
|
||||
except DatabaseError:
|
||||
pass
|
||||
except DatabaseError as exc:
|
||||
logger.exception('copy data from old constance table to a new one')
|
||||
|
||||
Constance = apps.get_model('constance', 'Constance')
|
||||
sequence_sql = connection.ops.sequence_reset_sql(no_style(), [Constance])
|
||||
|
|
|
|||
Loading…
Reference in a new issue