-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from jdufresne/operational-error
Convert the text NULL data to the empty string before schema changes
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
schedule/migrations/0006_update_text_fields_empty_string.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [ | ||
] |