Skip to content

Commit

Permalink
homew/migrations: fix error json field cannot be NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
goapunk authored and m4ra committed Nov 2, 2023
1 parent d1e7629 commit 09c4e1c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/home/migrations/0003_streamfield_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@
import wagtail.fields


def empty_to_valid_json(apps, schema_editor):
HomePage = apps.get_model("apps_home", "HomePage")

q_homepage = HomePage.objects.all()
if q_homepage:
for homepage in q_homepage:
if len(homepage.body) == 0:
homepage.body = "{}"
homepage.save()


class Migration(migrations.Migration):

dependencies = [
('apps_home', '0002_create_homepage'),
]

operations = [
migrations.RunPython(empty_to_valid_json),
migrations.AlterField(
model_name='homepage',
name='body',
Expand Down
4 changes: 4 additions & 0 deletions changelog/_1118.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

### Fix

- error json cannot be NULL by setting homepage empty body to {} in an earlier migration

0 comments on commit 09c4e1c

Please sign in to comment.