From 126e8a5a53e5c5ef4804d4a129b701395571a15f Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sun, 28 Jan 2024 08:22:04 +0100 Subject: [PATCH] fixed FDC migration --- cookbook/migrations/0204_propertytype_fdc_id.py | 6 ------ ...0205_alter_food_fdc_id_alter_propertytype_fdc_id.py | 10 +++++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cookbook/migrations/0204_propertytype_fdc_id.py b/cookbook/migrations/0204_propertytype_fdc_id.py index 705984632..e57dea391 100644 --- a/cookbook/migrations/0204_propertytype_fdc_id.py +++ b/cookbook/migrations/0204_propertytype_fdc_id.py @@ -4,11 +4,6 @@ from django.db import migrations, models from django_scopes import scopes_disabled -def fix_fdc_ids(apps, schema_editor): - with scopes_disabled(): - # in case any food had a non digit fdc ID before this migration, remove it - Food = apps.get_model('cookbook', 'Food') - Food.objects.exclude(fdc_id__regex=r'^\d+$').exclude(fdc_id=None).update(fdc_id=None) class Migration(migrations.Migration): @@ -17,7 +12,6 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(fix_fdc_ids), migrations.AddField( model_name='propertytype', name='fdc_id', diff --git a/cookbook/migrations/0205_alter_food_fdc_id_alter_propertytype_fdc_id.py b/cookbook/migrations/0205_alter_food_fdc_id_alter_propertytype_fdc_id.py index 9f57e4434..96b19f26e 100644 --- a/cookbook/migrations/0205_alter_food_fdc_id_alter_propertytype_fdc_id.py +++ b/cookbook/migrations/0205_alter_food_fdc_id_alter_propertytype_fdc_id.py @@ -1,15 +1,23 @@ # Generated by Django 4.2.7 on 2023-11-29 19:44 from django.db import migrations, models +from django_scopes import scopes_disabled + + +def fix_fdc_ids(apps, schema_editor): + with scopes_disabled(): + # in case any food had a non digit fdc ID before this migration, remove it + Food = apps.get_model('cookbook', 'Food') + Food.objects.exclude(fdc_id__regex=r'^\d+$').exclude(fdc_id=None).update(fdc_id=None) class Migration(migrations.Migration): - dependencies = [ ('cookbook', '0204_propertytype_fdc_id'), ] operations = [ + migrations.RunPython(fix_fdc_ids), migrations.AlterField( model_name='food', name='fdc_id',