0👍
If your problem can be reduced to the last point, you can avoid setting your global variable during the migration with:
import sys
if 'makemigrations' not in sys.argv and 'migrate' not in sys.argv:
# variable setting here
Source:stackexchange.com