Skip to main content

Command Palette

Search for a command to run...

Use strings, not constants in Django migrations

Published
1 min read
F

React, Django and SQL developer at Forma.ai

:x:

# migrations/0001_my_migration.py
from my_file import MY_CONSTANT
MyModel.objects.get_or_create(name=MY_CONSTANT)

:white_check_mark:

# migrations/0001_my_migration.py
MyModel.objects.get_or_create(name="my-constant")

Why

  1. value of LOCALIZATION.BUNDLE__SYNC could change

  2. After the change, the migration behaves differently than when it was first written

    1. might even fail 😱

    2. (we all know how terrifying failing migrations are 😭)