title: Django3.x - Heroku - raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
body: <p>I need your help colleagues. I am trying to deploy my Django Project on Heroku but I am getting a seemingly simple error but I have struggled to debug it for days. I would appreciate detailed help, I am a newbie. Thanking you in advance.</p>
  
  <p><strong>Background</strong> I have hidden foldername because it is also a domainname I want to register.
  I have python 3.6.8 and Django 2.1.1 on a windows10 machine and Heroku PaaS. At first I was using Django 2.2 then downgraded to Django 2.1. by command <code>pipenv install djang0==2.1.1</code><br>
  Project works perfectly on local/development server i.e <code>python manage runserver</code> works .<br>
  The secret key is set <code>SECRET_KEY = os.environ.get('SECRET')</code>, I have also tried hard coding <code>SECRET_KEY = 'my-secret-key'</code> but no difference.<br>
  I have <code>os.environ.setdefault('DJANGO_SETTINGS_MODULE', '*foldername.settings.testing')</code> correctly set in wsgi.py &amp; manage.py</p>
  
  <p><strong>Other Settings</strong>
  My Procfile for Heroku has <code>web: gunicorn *foldername.wsgi:application --log-file -</code>. I have a <code>requirements</code> and a <code>runtime.txt</code> files.</p>
  
  <p><strong>Error</strong> When I run <code>$ heroku run python manage.py migrate</code>        </p>
  
  <pre><code>Running python manage.py migrate on ⬢ thawing-thicket-02648... up, run.2948 (Free)
  Traceback (most recent call last):
    File "manage.py", line 22, in &lt;module&gt;
      main()
    File "manage.py", line 18, in main
      execute_from_command_line(sys.argv)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
      utility.execute()
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 224, in fetch_command
      klass = load_command_class(app_name, subcommand)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 36, in load_command_class
      module = import_module('%s.management.commands.%s' % (app_name, name))
    File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "&lt;frozen importlib._bootstrap&gt;", line 994, in _gcd_import
    File "&lt;frozen importlib._bootstrap&gt;", line 971, in _find_and_load
    File "&lt;frozen importlib._bootstrap&gt;", line 955, in _find_and_load_unlocked
    File "&lt;frozen importlib._bootstrap&gt;", line 665, in _load_unlocked
    File "&lt;frozen importlib._bootstrap_external&gt;", line 678, in exec_module
    File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed
    File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 14, in &lt;module&gt;
      from django.db.migrations.autodetector import MigrationAutodetector
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/autodetector.py", line 11, in &lt;module&gt;
      from django.db.migrations.questioner import MigrationQuestioner
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/questioner.py", line 9, in &lt;module&gt;
      from .loader import MigrationLoader
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/loader.py", line 8, in &lt;module&gt;
      from django.db.migrations.recorder import MigrationRecorder
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 9, in &lt;module&gt;
      class MigrationRecorder:
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 22, in MigrationRecorder
      class Migration(models.Model):
    File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/base.py", line 87, in __new__
      app_config = apps.get_containing_app_config(module)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 249, in get_containing_app_config
      self.check_apps_ready()
    File "/app/.heroku/python/lib/python3.6/site-packages/django/apps/registry.py", line 131, in check_apps_ready
      settings.INSTALLED_APPS
    File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
      self._setup(name)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
      self._wrapped = Settings(settings_module)
    File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 126, in __init__
      raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
  django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
  </code></pre>
  
  <p>Running <code>$ heroku logs --tail</code> produces       </p>
  
  <pre><code>2020-01-29T15:56:40.652606+00:00 app[web.1]: self.reap_workers()
  2020-01-29T15:56:40.652609+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
  2020-01-29T15:56:40.652893+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
  2020-01-29T15:56:40.652896+00:00 app[web.1]: gunicorn.errors.HaltServer: &lt;HaltServer 'Worker failed to boot.' 3&gt;
  2020-01-29T15:56:40.745655+00:00 heroku[web.1]: State changed from starting to crashed
  2020-01-29T15:56:40.725433+00:00 heroku[web.1]: Process exited with status 1
  2020-01-29T16:21:03.239311+00:00 app[api]: Starting process with command `python manage.py migrate` by user developers@email.com
  2020-01-29T16:21:11.782005+00:00 heroku[run.2948]: State changed from starting to up
  2020-01-29T16:21:11.639515+00:00 heroku[run.2948]: Awaiting client
  2020-01-29T16:21:11.664869+00:00 heroku[run.2948]: Starting process with command `python manage.py migrate`
  2020-01-29T16:21:16.264816+00:00 heroku[run.2948]: State changed from up to complete
  2020-01-29T16:21:16.241764+00:00 heroku[run.2948]: Process exited with status 1
  2020-01-29T16:23:33.250194+00:00 heroku[web.1]: State changed from crashed to starting
  2020-01-29T16:23:39.991409+00:00 heroku[web.1]: Starting process with command `gunicorn foldername.wsgi --log-file -`
  2020-01-29T16:23:42.075462+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [4] [INFO] Starting gunicorn 20.0.4
  2020-01-29T16:23:42.076104+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [4] [INFO] Listening at: http://0.0.0.0:34607 (4)
  2020-01-29T16:23:42.076210+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [4] [INFO] Using worker: sync
  2020-01-29T16:23:42.080161+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [10] [INFO] Booting worker with pid: 10
  2020-01-29T16:23:42.131810+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [11] [INFO] Booting worker with pid: 11
  2020-01-29T16:23:42.302136+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [10] [ERROR] Exception in worker process
  2020-01-29T16:23:42.302140+00:00 app[web.1]: Traceback (most recent call last):
  2020-01-29T16:23:42.302160+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
  2020-01-29T16:23:42.302163+00:00 app[web.1]: worker.init_process()
  2020-01-29T16:23:42.302165+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
  2020-01-29T16:23:42.302167+00:00 app[web.1]: self.load_wsgi()
  2020-01-29T16:23:42.302169+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
  2020-01-29T16:23:42.302171+00:00 app[web.1]: self.wsgi = self.app.wsgi()
  2020-01-29T16:23:42.302173+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
  2020-01-29T16:23:42.302176+00:00 app[web.1]: self.callable = self.load()
  2020-01-29T16:23:42.302178+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
  2020-01-29T16:23:42.302180+00:00 app[web.1]: return self.load_wsgiapp()
  2020-01-29T16:23:42.302182+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
  2020-01-29T16:23:42.302184+00:00 app[web.1]: return util.import_app(self.app_uri)
  2020-01-29T16:23:42.302186+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
  2020-01-29T16:23:42.302188+00:00 app[web.1]: mod = importlib.import_module(module)
  2020-01-29T16:23:42.302190+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
  2020-01-29T16:23:42.302193+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
  2020-01-29T16:23:42.302195+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap&gt;", line 994, in _gcd_import
  2020-01-29T16:23:42.302197+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap&gt;", line 971, in _find_and_load
  2020-01-29T16:23:42.302199+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap&gt;", line 955, in _find_and_load_unlocked
  2020-01-29T16:23:42.302201+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap&gt;", line 665, in _load_unlocked
  2020-01-29T16:23:42.302203+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap_external&gt;", line 678, in exec_module
  2020-01-29T16:23:42.302205+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed
  2020-01-29T16:23:42.302207+00:00 app[web.1]: File "/app/foldername/wsgi.py", line 15, in &lt;module&gt;
  2020-01-29T16:23:42.302209+00:00 app[web.1]: application = get_wsgi_application()
  2020-01-29T16:23:42.302211+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
  2020-01-29T16:23:42.302213+00:00 app[web.1]: django.setup(set_prefix=False)
  2020-01-29T16:23:42.302215+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
  2020-01-29T16:23:42.302217+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  2020-01-29T16:23:42.302219+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
  2020-01-29T16:23:42.302221+00:00 app[web.1]: self._setup(name)
  2020-01-29T16:23:42.302224+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
  2020-01-29T16:23:42.302226+00:00 app[web.1]: self._wrapped = Settings(settings_module)
  2020-01-29T16:23:42.302228+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 126, in __init__
  2020-01-29T16:23:42.302230+00:00 app[web.1]: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
  2020-01-29T16:23:42.302240+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
  2020-01-29T16:23:42.302620+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [10] [INFO] Worker exiting (pid: 10)
  2020-01-29T16:23:42.322533+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [11] [ERROR] Exception in worker process
  2020-01-29T16:23:42.322537+00:00 app[web.1]: Traceback (most recent call last):
  2020-01-29T16:23:42.322539+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
  2020-01-29T16:23:42.322542+00:00 app[web.1]: worker.init_process()
  2020-01-29T16:23:42.322544+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
  2020-01-29T16:23:42.322545+00:00 app[web.1]: self.load_wsgi()
  2020-01-29T16:23:42.322547+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
  2020-01-29T16:23:42.322549+00:00 app[web.1]: self.wsgi = self.app.wsgi()
  2020-01-29T16:23:42.322552+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
  2020-01-29T16:23:42.322554+00:00 app[web.1]: self.callable = self.load()
  2020-01-29T16:23:42.322556+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
  2020-01-29T16:23:42.322558+00:00 app[web.1]: return self.load_wsgiapp()
  2020-01-29T16:23:42.322560+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
  2020-01-29T16:23:42.322562+00:00 app[web.1]: return util.import_app(self.app_uri)
  2020-01-29T16:23:42.322564+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
  2020-01-29T16:23:42.322566+00:00 app[web.1]: mod = importlib.import_module(module)
  2020-01-29T16:23:42.322568+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
  2020-01-29T16:23:42.322570+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
  2020-01-29T16:23:42.322572+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap&gt;", line 994, in _gcd_import
  2020-01-29T16:23:42.322574+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap&gt;", line 971, in _find_and_load
  2020-01-29T16:23:42.322576+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap&gt;", line 955, in _find_and_load_unlocked
  2020-01-29T16:23:42.322578+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap&gt;", line 665, in _load_unlocked
  2020-01-29T16:23:42.322580+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap_external&gt;", line 678, in exec_module
  2020-01-29T16:23:42.322582+00:00 app[web.1]: File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed
  2020-01-29T16:23:42.322584+00:00 app[web.1]: File "/app/foldername/wsgi.py", line 15, in &lt;module&gt;
  2020-01-29T16:23:42.322586+00:00 app[web.1]: application = get_wsgi_application()
  2020-01-29T16:23:42.322588+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
  2020-01-29T16:23:42.322590+00:00 app[web.1]: django.setup(set_prefix=False)
  2020-01-29T16:23:42.322592+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
  2020-01-29T16:23:42.322594+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  2020-01-29T16:23:42.322596+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
  2020-01-29T16:23:42.322598+00:00 app[web.1]: self._setup(name)
  2020-01-29T16:23:42.322600+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
  2020-01-29T16:23:42.322602+00:00 app[web.1]: self._wrapped = Settings(settings_module)
  2020-01-29T16:23:42.322604+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 126, in __init__
  2020-01-29T16:23:42.322606+00:00 app[web.1]: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
  2020-01-29T16:23:42.322609+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
  2020-01-29T16:23:42.322958+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [11] [INFO] Worker exiting (pid: 11)
  2020-01-29T16:23:42.449777+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [4] [INFO] Shutting down: Master
  2020-01-29T16:23:42.469241+00:00 app[web.1]: [2020-01-29 16:23:42 +0000] [4] [INFO] Reason: Worker failed to boot.
  2020-01-29T16:23:42.572344+00:00 heroku[web.1]: State changed from starting to crashed
  2020-01-29T16:23:42.557638+00:00 heroku[web.1]: Process exited with status 3
  
  </code></pre>
  
  <p>Normal <code>$ python manage.py migrate</code> without <code>heroku run</code> part does the migrations but app still won't start and error trace back from <code>$ heroku logs --tail</code> still present and the same</p>
  
  <p><a href="https://i.stack.imgur.com/Wztj8.jpg" rel="nofollow noreferrer">See my folder structure &amp; wsgi.py</a></p>
  
  <p><a href="https://i.stack.imgur.com/za6y2.jpg" rel="nofollow noreferrer">See my manage.py</a></p>
  
  <p><a href="https://i.stack.imgur.com/RGr1z.jpg" rel="nofollow noreferrer">Settings just to show secret key is in</a></p>