Skip to content

Commit

Permalink
Merge pull request #376 from jdufresne/operational-error
Browse files Browse the repository at this point in the history
Convert the text NULL data to the empty string before schema changes
  • Loading branch information
kimarakov committed Jan 3, 2018
2 parents cd4c32d + d3a6d23 commit 8ac3b66
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
40 changes: 40 additions & 0 deletions schedule/migrations/0006_update_text_fields_empty_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.db import migrations


def forwards(apps, schema_editor):
model_fields = [
('CalendarRelation', ['distinction']),
('Event', ['color_event', 'description']),
('EventRelation', ['distinction']),
('Occurrence', ['description', 'title']),
('Rule', ['params']),
]
for model_name, fields in model_fields:
model_class = apps.get_model('schedule', model_name)
for field_name in fields:
model_class.objects.filter(**{field_name: None}).update(**{field_name: ''})


def reverse(apps, schema_editor):
model_fields = [
('CalendarRelation', ['distinction']),
('Event', ['color_event', 'description']),
('EventRelation', ['distinction']),
('Occurrence', ['description', 'title']),
('Rule', ['params']),
]
for model_name, fields in model_fields:
model_class = apps.get_model('schedule', model_name)
for field_name in fields:
model_class.objects.filter(**{field_name: ''}).update(**{field_name: None})


class Migration(migrations.Migration):

dependencies = [
('schedule', '0003_auto_20160715_0028'),
]

operations = [
migrations.RunPython(forwards, reverse, elidable=True),
]
12 changes: 12 additions & 0 deletions schedule/migrations/0007_merge_text_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('schedule', '0006_update_text_fields_empty_string'),
('schedule', '0005_verbose_name_plural_for_calendar'),
]

operations = [
]

0 comments on commit 8ac3b66

Please sign in to comment.