Django Postgres test_database already exists

postgresql
circle.yml
django

#1

As per example of https://github.com/CircleCI-Public/circleci-demo-python-django/ 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 manage.py 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
        jobs:
          build:
            docker:
              # specify the version you desire here
              # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
              - image: circleci/python:3.6.4
                environment:
                  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 https://circleci.com/docs/2.0/circleci-images/
  # - image: circleci/postgres:9.4
  - image: circleci/postgres:9.6-alpine
    environment:
      POSTGRES_USER: root
      POSTGRES_DB: circle_test

steps:
  - checkout

  # Download and cache dependencies
  - restore_cache:
      keys:
      - 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:
      paths:
        - ./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
  # https://pytest.org
  # https://nose.readthedocs.io
  - run:
      name: run tests
      command: |
        . venv/bin/activate
        python manage.py test

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

#2

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.


#3

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