Use strings, not constants in Django migrations
Fullchee Zhang
1 min read
# migrations/0001_my_migration.py
from my_file import MY_CONSTANT
MyModel.objects.get_or_create(name=MY_CONSTANT)
# migrations/0001_my_migration.py
MyModel.objects.get_or_create(name="my-constant")
Why
value of
LOCALIZATION.BUNDLE__SYNC
could changeAfter the change, the migration behaves differently than when it was first written
might even fail ๐ฑ
(we all know how terrifying failing migrations are ๐ญ)
0
Subscribe to my newsletter
Read articles from Fullchee Zhang directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Fullchee Zhang
Fullchee Zhang
React, Django and SQL developer at Forma.ai