Django Postgres test_database already exists



As per example of minus the pipenv (which is just a different package manager), I have religiously followed CircleCIs example.

Now, the problem is that I get a timeout on my build. I ssh-ed into my build, found out that the error happens because my test runner hangs with the following error.
Creating test database for alias 'default'... Got an error creating the test database: database "test_circleci_test" already exists

Alright so I do python shell and print my settings

{'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'circle_test', 'USER': 'root', 'PASSWORD': '', 'HOST': 'localhost', 'PORT': '', 'CONN_MAX_AGE': 500, 'OPTIONS': {'sslmode': 'disable'}, 'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'TIME_ZONE': None, 'TEST': {'CHARSET': None, 'COLLATION': None, 'NAME': None, 'MIRROR': None}}

Everything as expected because circleci overwrites my db settings via database_url.

now, I’d love if someone could explain to my what am I doing wrong and if there is anything else I could try and refactor to make this work. thanks!

version: 2
              # specify the version you desire here
              # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
              - image: circleci/python:3.6.4
                  DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable

  # Specify service dependencies here if necessary
  # CircleCI maintains a library of pre-built images
  # documented at
  # - image: circleci/postgres:9.4
  - image: circleci/postgres:9.6-alpine
      POSTGRES_USER: root
      POSTGRES_DB: circle_test

  - checkout

  # Download and cache dependencies
  - restore_cache:
      - v1-dependencies-{{ checksum "requirements.txt" }}
      # fallback to using the latest cache if no exact match is found
      - v1-dependencies-

  - run:
      name: install dependencies
      command: |
        python3 -m venv venv
        . venv/bin/activate
        pip install -r requirements.txt

  - save_cache:
        - ./venv
      key: v1-dependencies-{{ checksum "requirements.txt" }}

  # run tests!
  # this example uses Django's built-in test-runner
  # other common Python testing frameworks include pytest and nose
  - run:
      name: run tests
      command: |
        . venv/bin/activate
        python test

  - store_artifacts:
      path: test-reports
      destination: test-reports


Something is (a) creating your database, and then (b) something else is trying to recreate that database. You need to find one of them and suppress one, or put a DROP DATABASE test_circleci_test in between them, if that is easier.


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.