Add migration to populate site_values in SiteConfigurationHistory
Right now the ORM is very unhappy about the JSONField `site_values` in SiteConfigurationHistory containing non-JSON (empty strings). We cannot even write a data migration using the ORM to populate the field because that causes a JSONDeserializationError. Therefore, we must bypass the ORM and populate the values with raw SQL. DENG-18
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
forward_sql = """
|
||||
UPDATE
|
||||
site_configuration_siteconfigurationhistory
|
||||
SET
|
||||
site_values = '{}';
|
||||
"""
|
||||
|
||||
reverse_sql = """
|
||||
UPDATE
|
||||
site_configuration_siteconfigurationhistory
|
||||
SET
|
||||
site_values = '';
|
||||
"""
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('site_configuration', '0004_add_site_values_field'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunSQL(forward_sql, reverse_sql=reverse_sql),
|
||||
]
|
||||
Reference in New Issue
Block a user