I’ve got a postgres DB which Django successfully connects to but when trying to create a new model I’m getting the error settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
I know settings.DATABASES is correctly configured as I’ve already created models which then Django used to create tables in the DB but for whatever reason it is now causing this error. You can also see that I have already “supplied the ENGINE value”.
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': os.environ['POSTGRES_DB'], 'USER': os.environ['POSTGRES_USER'], 'PASSWORD': os.environ['POSTGRES_PASSWORD'], 'HOST': 'db', 'POST': '5432', } }
All help is appreciated.
Advertisement
Answer
Turns out I’m an idiot.
I’m using docker and I forgot that I need to enter the container to do DB migrations 🤦♂️
The exact cause of this error is that the dockerfile creates an environment variable called “DJANGO_SETTINGS_MODULE” which Django looks for and the value is the name of an alternate file to be used for settings. As I wasn’t in the docker container, this environment variable wasn’t available so it was using the default settings.py which has had its DB settings removed.