1

I am trying to deploy a web on Heroku. When I run heroku run python manage.py migrate I will get some errors: django.core.exceptions.ImproperlyConfigured: Set the DJANGO_SENTRY_DSN environment variable

I read the documentation on Cookiecutter, the document said I have to specify these values. But it didn't tell me what's the purpose and the method. I am wondering do I really have to specify all this values?

DJANGO_AWS_ACCESS_KEY_ID    
DJANGO_AWS_SECRET_ACCESS_KEY    
DJANGO_AWS_STORAGE_BUCKET_NAME  
DJANGO_SENTRY_DSN
DJANGO_SENTRY_CLIENT
DJANGO_SENTRY_LOG_LEVEL 
DJANGO_MAILGUN_API_KEY  
DJANGO_MAILGUN_SERVER_NAME

Logs:

$ heroku logs --app glacial-forest-93266 --dyno run.9155
2017-02-23T03:28:44.634830+00:00 heroku[run.9155]: Starting process with command `python manage.py migrate`
2017-02-23T03:28:45.292164+00:00 heroku[run.9155]: State changed from starting to up
2017-02-23T03:28:47.487454+00:00 heroku[run.9155]: Process exited with status 1
2017-02-23T03:28:47.336279+00:00 app[run.9155]: /app/.heroku/python/lib/python3.5/site-packages/environ/environ.py:608: UserWarning: /app/co
nfig/settings/.env doesn't exist - if you're not configuring your environment separately, create one.
2017-02-23T03:28:47.359554+00:00 app[run.9155]: Traceback (most recent call last):
2017-02-23T03:28:47.359557+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/environ/environ.py", line 264, in ge
t_value
2017-02-23T03:28:47.336297+00:00 app[run.9155]:   "environment separately, create one." % env_file)
2017-02-23T03:28:47.359787+00:00 app[run.9155]:     value = self.ENVIRON[var]
2017-02-23T03:28:47.359791+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/os.py", line 683, in __getitem__
2017-02-23T03:28:47.360099+00:00 app[run.9155]:     raise KeyError(key) from None
2017-02-23T03:28:47.360103+00:00 app[run.9155]: KeyError: 'DJANGO_SENTRY_DSN'
2017-02-23T03:28:47.360105+00:00 app[run.9155]:
2017-02-23T03:28:47.360106+00:00 app[run.9155]: During handling of the above exception, another exception occurred:
2017-02-23T03:28:47.360107+00:00 app[run.9155]:
2017-02-23T03:28:47.360109+00:00 app[run.9155]: Traceback (most recent call last):
2017-02-23T03:28:47.360130+00:00 app[run.9155]:   File "manage.py", line 23, in <module>
2017-02-23T03:28:47.360228+00:00 app[run.9155]:     execute_from_command_line(sys.argv)
2017-02-23T03:28:47.360246+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
 line 367, in execute_from_command_line
2017-02-23T03:28:47.360425+00:00 app[run.9155]:     utility.execute()
2017-02-23T03:28:47.360427+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
 line 359, in execute
2017-02-23T03:28:47.360606+00:00 app[run.9155]:     self.fetch_command(subcommand).run_from_argv(self.argv)
2017-02-23T03:28:47.360609+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
 line 208, in fetch_command
2017-02-23T03:28:47.360739+00:00 app[run.9155]:     klass = load_command_class(app_name, subcommand)
2017-02-23T03:28:47.360740+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py",
 line 40, in load_command_class
2017-02-23T03:28:47.360838+00:00 app[run.9155]:     module = import_module('%s.management.commands.%s' % (app_name, name))
2017-02-23T03:28:47.360960+00:00 app[run.9155]:     return _bootstrap._gcd_import(name[level:], package, level)
2017-02-23T03:28:47.360840+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/importlib/__init__.py", line 126, in import_module

2017-02-23T03:28:47.360962+00:00 app[run.9155]:   File "<frozen importlib._bootstrap>", line 986, in _gcd_import
2017-02-23T03:28:47.361192+00:00 app[run.9155]:   File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
2017-02-23T03:28:47.361105+00:00 app[run.9155]:   File "<frozen importlib._bootstrap>", line 969, in _find_and_load
2017-02-23T03:28:47.361278+00:00 app[run.9155]:   File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
2017-02-23T03:28:47.361364+00:00 app[run.9155]:   File "<frozen importlib._bootstrap_external>", line 662, in exec_module
2017-02-23T03:28:47.361554+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/commands/migr
ate.py", line 15, in <module>
2017-02-23T03:28:47.361466+00:00 app[run.9155]:   File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
2017-02-23T03:28:47.361645+00:00 app[run.9155]:     from django.db.migrations.autodetector import MigrationAutodetector
2017-02-23T03:28:47.361645+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/autodetector.py
", line 13, in <module>
2017-02-23T03:28:47.361739+00:00 app[run.9155]:     from django.db.migrations.questioner import MigrationQuestioner
2017-02-23T03:28:47.361740+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/questioner.py",
 line 12, in <module>
2017-02-23T03:28:47.361832+00:00 app[run.9155]:     from .loader import MigrationLoader
2017-02-23T03:28:47.361833+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/loader.py", lin
e 10, in <module>
2017-02-23T03:28:47.361923+00:00 app[run.9155]:     from django.db.migrations.recorder import MigrationRecorder
2017-02-23T03:28:47.361924+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/recorder.py", l
ine 12, in <module>
2017-02-23T03:28:47.362014+00:00 app[run.9155]:     class MigrationRecorder(object):
2017-02-23T03:28:47.362015+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/recorder.py", l
ine 26, in MigrationRecorder
2017-02-23T03:28:47.362109+00:00 app[run.9155]:     class Migration(models.Model):
2017-02-23T03:28:47.362110+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/migrations/recorder.py", l
ine 27, in Migration
2017-02-23T03:28:47.362206+00:00 app[run.9155]:     app = models.CharField(max_length=255)
2017-02-23T03:28:47.362206+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 1043, in __init__
2017-02-23T03:28:47.362557+00:00 app[run.9155]:     super(CharField, self).__init__(*args, **kwargs)
2017-02-23T03:28:47.362558+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 166, in __init__
2017-02-23T03:28:47.362682+00:00 app[run.9155]:     self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
2017-02-23T03:28:47.362683+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 53, i
n __getattr__
2017-02-23T03:28:47.362790+00:00 app[run.9155]:     self._setup(name)
2017-02-23T03:28:47.362791+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 41, i
n _setup
2017-02-23T03:28:47.362927+00:00 app[run.9155]:     self._wrapped = Settings(settings_module)
2017-02-23T03:28:47.362929+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/django/conf/__init__.py", line 97, i
n __init__
2017-02-23T03:28:47.363042+00:00 app[run.9155]:     mod = importlib.import_module(self.SETTINGS_MODULE)
2017-02-23T03:28:47.363043+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/importlib/__init__.py", line 126, in import_module

2017-02-23T03:28:47.363153+00:00 app[run.9155]:     return _bootstrap._gcd_import(name[level:], package, level)
2017-02-23T03:28:47.363154+00:00 app[run.9155]:   File "/app/config/settings/production.py", line 161, in <module>
2017-02-23T03:28:47.363279+00:00 app[run.9155]:     SENTRY_DSN = env('DJANGO_SENTRY_DSN')
2017-02-23T03:28:47.363394+00:00 app[run.9155]:     return self.get_value(var, cast=cast, default=default, parse_default=parse_default)
2017-02-23T03:28:47.363395+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/environ/environ.py", line 268, in ge
t_value
2017-02-23T03:28:47.363558+00:00 app[run.9155]:     raise ImproperlyConfigured(error_msg)
2017-02-23T03:28:47.363281+00:00 app[run.9155]:   File "/app/.heroku/python/lib/python3.5/site-packages/environ/environ.py", line 126, in __
call__
2017-02-23T03:28:47.363560+00:00 app[run.9155]: django.core.exceptions.ImproperlyConfigured: Set the DJANGO_SENTRY_DSN environment variable
2017-02-23T03:28:47.501504+00:00 heroku[run.9155]: State changed from up to complete
Eugene Liu
  • 81
  • 5
  • I'm doing the same thing. Just defined those env variables as empty. The project is deployed, but I get a 500 error. Working on it. – Jorge Arévalo Feb 24 '17 at 21:42

2 Answers2

3

You could check all the necessary settings here: http://cookiecutter-django.readthedocs.io/en/latest/settings.html

Generally, you could just define a blank value for it like:

heroku config:set DJANGO_AWS_ACCESS_KEY_ID=''

Specifically, you can leave the AWS values blank if you won't upload to S3, you can leave SENTRY values blank if you disable sentry, and you can leave MAILGUN app if you disable mailgun.

Eman
  • 81
  • 1
  • 5
0

You are using the production.py settings inside /config/settings by running this line:

heroku config:set DJANGO_SETTINGS_MODULE='config.settings.production'

Either make a separate settings file for heroku not having SENTRY and other services, else just uncomment lines initializing those services. Also you'll want to keep the /media and /static local if you're not using aws.

Hrishikesh
  • 335
  • 1
  • 13