Django "Got an error creating the test database: database already exists" in CI
Django tries to create a fresh test_<db> before running tests. A leftover database from a cancelled or parallel run already holds that name, so creation fails and Django prompts to delete it, which is non-interactive in CI.
What this error means
The test runner halts with "Got an error creating the test database: database \"test_app\" already exists" and waits on a "Type yes to delete it" prompt that never gets input.
Got an error creating the test database: database "test_app" already exists
Type 'yes' if you would like to try deleting the test database 'test_app', or 'no' to cancel:Common causes
A previous run left the test database
A cancelled job did not tear down test_app, so the next run collides on creation.
Parallel jobs share one database server
Two jobs target the same Postgres and race to create the same test database name.
How to fix it
Reuse the database with --keepdb
Tell the runner to reuse an existing test database instead of recreating it, avoiding the collision and the prompt.
python manage.py test --keepdb --noinputRun non-interactively against a clean service
- Use a fresh Postgres service container per job so no leftover database exists.
- Pass
--noinputso the runner never blocks on the delete prompt. - For parallel jobs, give each a distinct database or service.
python manage.py test --noinputHow to prevent it
- Use an ephemeral DB service container so each job starts clean.
- Always pass --noinput so prompts never hang the job.
- Isolate parallel jobs with distinct database names.