Hi everyone. Please help me figure this out. I have two options specified in my Django settings file for the DATABASES. If DEBUG=True, the project uses sqlite3 and if DEBUG=False, it uses PostgreSQL.
So, here's the question: when I start up the project locally in Docker containers, I use a PostgreSQL container (as stated in the Docker Compose file), even though in my .env file DEBUG=True, and Django should theoretically want sqlite3 (as specified in the Django settings). Why isn't there a conflict?
#Databases settings and docker
5 messages · Page 1 of 1 (latest)
DATABASES = {
'production': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv('POSTGRES_DB', 'django'),
'USER': os.getenv('POSTGRES_USER', 'django'),
'PASSWORD': os.getenv('POSTGRES_PASSWORD', ''),
'HOST': os.getenv('DB_HOST', ''),
'PORT': os.getenv('DB_PORT', 5432)
},
'dev': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
DATABASES['default'] = DATABASES['dev' if DEBUG else 'production']
I'm not sure what exactly is your issue, do you want to use postgresql in when you develop locally with docker? I'd rephrase and expand on your question "why isn't there a conflict".
In any case you might benefit from using https://pypi.org/project/dj-database-url/, which would allow you to set DATABASE_URL=sqlite://dev.db and DATABASE_URL=postgres:///db for example and not have to worry about setting the ENGINE manually
If your docker compose file says to start a postgres container, docker will start it. If your settings point to SQLite, the postgres container will just sit idle with no connections and no data.