Enviroments variables and migrations not working in django

I have following problem. I, starting app with structure like this: In env_vasr.sh I want to keep all the credentials etc. I source this file and variables are in env. However, when I run django-admin migrate, I get the following problem: Can anyone tell me what is the problem please.


├── eMenue

│   ├── eMenue

│   │   ├── asgi.py

│   │   ├── __init__.py

│   │   ├── __pycache__

│   │   │   ├── __init__.cpython-310.pyc

│   │   │   └── settings.cpython-310.pyc

│   │   ├── settings.py

│   │   ├── urls.py

│   │   └── wsgi.py

│   ├── eMenueApp

│   │   ├── admin.py

│   │   ├── apps.py

│   │   ├── __init__.py

│   │   ├── migrations

│   │   │   └── __init__.py

│   │   ├── models.py

│   │   ├── tests.py

│   │   └── views.py

│   └── manage.py

├── env_vars.sh

├── global_settings.json

├── requirements.txt


This the output from the django-admin migrate command: With hardcoded values it worked fine. However, I created ne project after to add env variables from file.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/michal/devel/eMenue/venv/bin/django-admin", line 8, in <module>
    sys.exit(execute_from_command_line())
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/core/management/base.py", line 415, in run_from_argv
    connections.close_all()
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/utils/connection.py", line 84, in close_all
    for conn in self.all(initialized_only=True):
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/utils/connection.py", line 76, in all
    return [
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/utils/connection.py", line 73, in __iter__
    return iter(self.settings)
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/utils/connection.py", line 45, in settings
    self._settings = self.configure_settings(self._settings)
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/db/utils.py", line 148, in configure_settings
    databases = super().configure_settings(databases)
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/utils/connection.py", line 50, in configure_settings
    settings = getattr(django_settings, self.settings_name)
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 92, in __getattr__
    self._setup(name)
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 79, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/michal/devel/eMenue/venv/lib/python3.10/site-packages/django/conf/__init__.py", line 190, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'eMenue'

You got typo in you database config 'USER': os.geten['DB_USER'],

change it on 'USER': os.getenv['DB_USER']

Back to Top