Fix remove_null_from_text_fields migration
This commit is contained in:
parent
1256d0f52b
commit
f962a7e0fa
@ -5,8 +5,6 @@ from __future__ import unicode_literals
|
||||
from django.db import migrations, models
|
||||
import multiselectfield.db.fields
|
||||
|
||||
from apps.map.models import CaseStudy
|
||||
|
||||
string_fields = [
|
||||
'additional_technical_details',
|
||||
'associated_infrastructure',
|
||||
@ -58,13 +56,17 @@ string_fields = [
|
||||
def remove_nulls(apps, schema_editor):
|
||||
# We can't import the Person model directly as it may be a newer
|
||||
# version than this migration expects. We use the historical version.
|
||||
study = apps.get_model('map', 'CaseStudy')
|
||||
CaseStudy = apps.get_model('map', 'CaseStudy')
|
||||
for study in CaseStudy.objects.all():
|
||||
for field in string_fields:
|
||||
if getattr(study, field) == None:
|
||||
setattr(study, field, '')
|
||||
|
||||
try:
|
||||
study.save()
|
||||
except:
|
||||
from pdb import set_trace; set_trace()
|
||||
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@ -74,5 +76,5 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(remove_nulls),
|
||||
migrations.RunPython(remove_nulls, migrations.RunPython.noop),
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user