Change: Fix DB_ENGINE=postgres being silently ignored
Date: 2026-09-11
Goal
Make DB_ENGINE=postgres actually select PostgreSQL, regardless of DEBUG. Previously the
Postgres branch was gated on not DEBUG, so with DEBUG true (the default, and the state
inside the Docker container) the app fell back to SQLite even though DB_ENGINE=postgres
and DATABASE_URL were set.
What changed
| Area | Change |
|---|---|
| Database selection | config/settings.py now chooses the backend from DB_ENGINE alone (if DB_ENGINE in ("postgres", "postgresql")); the not DEBUG and condition was removed. |
| Error message | With DB_ENGINE=postgres and no DATABASE_URL, startup raises a clear ImproperlyConfigured instead of a bare KeyError. |
| Compose env loading | docker-compose.yml web now declares an optional env_file: .env (required: false), so the whole .env (DEBUG, SECRET_KEY, SSO, MCP, search tuning, ...) reaches the container. Explicit environment entries still take precedence, and Coolify can still deploy with no .env file. |
| Compose DEBUG | web.environment sets DJANGO_DEBUG: ${DJANGO_DEBUG:-0}, so the container's DEBUG reflects .env and defaults off in Docker. |
Notes
- The SQLite fallback is still the default only when
DB_ENGINEis unset or set tosqlite, so local development without a.envis unchanged. - This corrects the earlier production-Docker plan's locked decision, which specified
DB_ENGINEas the sole selector (noDEBUGcoupling). env_file.requiredneeds Docker Compose v2.24+; older hosts must keep a real.envor rely on Coolify-injected variables.- No model, migration, or schema changes.
User validation
- With
DB_ENGINE=postgresandDATABASE_URLset:python manage.py shell -c "from django.conf import settings; print(settings.DATABASES['default']['ENGINE'])"printsdjango.db.backends.postgresql. - Same command with
DJANGO_DEBUG=1still prints the Postgres backend. - With
DB_ENGINE=postgresand noDATABASE_URL, startup raises the clearImproperlyConfiguredmessage. - With
DB_ENGINEunset, the backend isdjango.db.backends.sqlite3. - Set
DJANGO_DEBUG=1in.env, rundocker compose config(showsDJANGO_DEBUG: "1"), thendocker compose exec web python manage.py shell -c "from django.conf import settings; print(settings.DEBUG)"printsTrue; set it to0and confirmFalse.