Home > Enterprise >  django.core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable
django.core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable

Time:01-02

I annotate text data (building data sets for named entity recognition models) using AlpacaTag, which was designed using Python on Django. I followed the steps of AlpacaTag installation guide When I run the command
python manage.py migrate
(I come to find information, to know this is the Django's command of database migration),
The program threw an exception:

Traceback (most recent call last):
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/environ/environ.py", line 367, in get_value
    value = self.ENVIRON[var]
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'SECRET_KEY'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/django/core/management/base.py", line 86, in wrapped
    saved_locale = translation.get_language()
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/django/utils/translation/__init__.py", line 254, in get_language
    return _trans.get_language()
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/django/utils/translation/__init__.py", line 57, in __getattr__
    if settings.USE_I18N:
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/django/conf/__init__.py", line 69, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/django/conf/__init__.py", line 170, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/duzx21/AlpacaTag/annotation/AlpacaTag/app/settings.py", line 33, in <module>
    SECRET_KEY = env('SECRET_KEY')
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/environ/environ.py", line 179, in __call__
    parse_default=parse_default
  File "/home/duzx21/miniconda3/envs/alpacatag/lib/python3.6/site-packages/environ/environ.py", line 371, in get_value
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable

This is defined in the setting.py file:

SECRET_KEY = env('SECRET_KEY') 

I don't know how to solve this problem, then randomly generated a string of text as the SECRET_KEY:

SECRET_KEY='2ap4_#)wk@5)3lsh6idzxwaouy6)*(5z#w(3atk0           
  • Related