django.core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable
See original GitHub issueTraceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/environ/environ.py", line 273, in get_value
value = self.ENVIRON[var]
File "/usr/local/lib/python3.8/os.py", line 675, in __getitem__
raise KeyError(key) from None
KeyError: 'DATABASE_URL'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/app/manage.py", line 31, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 67, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 76, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 63, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 142, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/app/config/settings/local.py", line 1, in <module>
from .base import * # noqa
File "/app/config/settings/base.py", line 44, in <module>
DATABASES = {"default": env.db("DATABASE_URL")}
File "/usr/local/lib/python3.8/site-packages/environ/environ.py", line 204, in db_url
return self.db_url_config(self.get_value(var, default=default), engine=engine)
File "/usr/local/lib/python3.8/site-packages/environ/environ.py", line 277, in get_value
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable
the errors happend when pycharm runserver, how to solve this?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:20 (8 by maintainers)
Top Results From Across the Web
Set the DATABASE_URL environment variable - Stack Overflow
DATABASES = { # read os.environ['DATABASE_URL'] and raises ImproperlyConfigured exception if not found 'default': env.db(), }. with this:
Read more >django.core.exceptions.ImproperlyConfigured: Set the ...
ImproperlyConfigured : Set the DATABASE_URL environment variable #2821 ... raise ImproperlyConfigured(error_msg) django.core.exceptions.
Read more >Set the DATABASE_URL environment variable : r/django
django.core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable. I get this error when I try to run py manage.py ...
Read more >DATABASE_URL environment variable error - Crowdbotics
I encountered this error with the current Django scaffold: django.core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable.
Read more >pydanny/cookiecutter-django - Gitter
core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable . Is there something I'm missing?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@TElphee01 Correct, it is set in entrypoint under the compose/django directory. If you want to run a command like shell, you’ll need to do
docker-compose -f local.yml run --rm django python manage.py shell
@habenhkt are you aware that you are asking a question in a closed Issue? Besides that, the issue section of github is for issues concerning the project. Your problem is more suitable for in QA site like stackoverflow or the discussion section.
Regarding your question, check the
env()
method, it is missing the keyworddefault
(settings.py, line 293).