I'm trying to deploy my Django project using Heroku, but now stuck with the empty SECRET_KEY problem when I run the heroku run python manage.py syncdb
command:
Traceback (most recent call last):
File "manage.py", line 10, in execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/init.py", line 338, in execute_from_command_line utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/init.py", line 330, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/init.py", line 190, in fetch_command klass = load_command_class(app_name, subcommand)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/init.py", line 40, in load_command_class module = import_module('%s.management.commands.%s' % (app_name, name))
File "/app/.heroku/python/lib/python2.7/importlib/init.py", line 37, in import_module import(name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 4, in from django.contrib.auth import get_user_model
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/init.py", line 7, in from django.middleware.csrf import rotate_token
File "/app/.heroku/python/lib/python2.7/site-packages/django/middleware/csrf.py", line 14, in from django.utils.cache import patch_vary_headers
File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/cache.py", line 26, in from django.core.cache import caches
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/cache/init.py", line 34, in if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/init.py", line 48, in getattr self._setup(name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/init.py", line 44, in _setup self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/init.py", line 113, in init raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.") django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
However, running python manage.py syncdb
is totally fine. In my settings.py
file, I even wrote the SECRET_EKY explicitly as:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '*$_99!t5u&#w&9boeq()=obq@rjdsfasdfa#8hp_5s%h-mh(hk'`
I still got the same problem. I wondered if the environment variable DJANGO_SETTINGS_MODULE was missing, but running heroku config
gave me (I replaced the information with xxx):
DATABASE_URL: xxx
DJANGO_SETTINGS_MODULE: xxx
SECRET_KEY: xxx
It seems that the relevant environment variables do exist. I really hope you could give me some suggestions. Thank you very much in advance.
SECRET_KEY
setting. The problem is that when django loads it tries to read the secret key from the settings file, but if no such file is loaded it will just fail with the SECRET_KEY must not be empty error. – Serafeimmanage.py
, it works; the error only occurs when I runheroku run manage.py
, so it must be something about my hekoru setup, but I just can't figure it out. – Yuan Tian