I have a GitHub workflow for Django and when it gets to migrating the database it gives the error
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
the secret key is stored in a .env
file and loaded with
from dotenv import load_dotenv
load_dotenv()
from pathlib import Path
env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)
SECRET_KEY = os.getenv("secret_key")
Here is the file tree
C:.
| db.sqlite3
| manage.py
|
\---djangosite
| .env
| asgi.py
| settings.py
| urls.py
| wsgi.py
| __init__.py
|
\---__pycache__
...
This is the manage.py, it is the regular django one with the load .env code from settings.py
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
from dotenv import load_dotenv
load_dotenv()
from pathlib import Path
env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangosite.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
when I run manage.py
on my PC it loads the key and runs the server, but GitHub gives the error above.
How do I stop this error from happening?