Django test - unable to delete and update test database

I am running Django 1.9, Postgres 9.5.1 on Mac OS X

When i started /manage.py test --settings=myproj.settings.local

I get:

Creating test database for alias 'default'...
Creating test database for alias 'userlocation'...
Got an error creating the test database: database "test_myproj" already exists

Type 'yes' if you would like to try deleting the test database 'test_myproj', or 'no' to cancel: yes
Destroying old test database for alias 'userlocation'...
Got an error recreating the test database: database "test_myproj" is being accessed by other users
DETAIL:  There is 1 other session using the database.

So, according to this post , I ran:

SELECT 
    pg_terminate_backend(pid) 
FROM 
    pg_stat_activity 
WHERE 

    pid <> pg_backend_pid()

    AND datname = 'test_myproj'
    ;

Go to DROP DATABASE test_myprojand try running the tests again just to get an errorDETAIL: There is 1 other session using the database.

As a list of processes, nothing is bound to a database. I kill the server and restart, but the management command to run the tests still gives me the error that there is another session connected to the database.

This is a real head scraper, I have never seen this before - is there anyone else?

My settings:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'myproj',
        'USER': 'myuser',
        'PASSWORD': 'mypass',
        'HOST': 'localhost',
        'PORT': '',
    },
    'userlocation': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'og_myproj',
        'USER': 'og_myuser',
        'PASSWORD': 'mypasswd',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}
+4
source share
2 answers

sudo /etc/init.d/postgresql restart ,

+5

: 1 .

, pg admin ui django . db django/psycopg2 , - , db. pg admin, . , db ui. .

0

Source: https://habr.com/ru/post/1651555/


All Articles