28š
TL;DR
If you just want the solution, here it is.
Make sure that your Postgres server has a āpostgresā database. You can check by connecting via psql
, and running /list
or /l
. You can create the database by running: CREATE DATABASE postgres
in psql.
Extended
Django prefers to not run āinitialization queriesā (presumably things like creating the test database) from the ādefaultā database specified in your DATABASES
setting. This is presumed to be the production database, so it would be in Djangoās best interests to not mess around there.
This is why at the beginning of the tests, this is shown (ignore my filesystem):
/Users/dcgoss/Desktop/Pickle/PickleBackend/venv/lib/python3.4/site-packages/django/db/backends/postgresql/base.py:247:
RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed
(for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the default database instead.
RuntimeWarning
Django looks for a database named āpostgresā on the host specified in your DATABASES
settings, this is where it runs the queries to create and delete your test database. (Note: Django does not need the āpostgresā database to be explicitly specified in your settings, it just looks for it on whatever database server is specified in your settings).
It appears that if this āpostgresā database does not exist, Django can create the test database and run the tests, but it cannot delete the test database. This may be because Postgres does not allow you to drop the database you are currently connected to, however to me it seems that there is no reason that Django couldnāt just drop the test database from the ādefaultā (production) database specified in the settings. I presume it is using the ādefaultā database to create the test database, so it seems thereās no reason why it canāt delete it as well.
Regardless, the solution was just to create that āpostgresā database with a simple SQL statement: CREATE DATABASE postgres
. After that database was created, everything worked fine.
7š
If postgres database exists, try adding access to āpostgresā database in pg_hba.conf. Refer: https://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html
- Using a custom form in a modelformset factory?
- Deploying existing Django app on Heroku
- How do I redefine functions in python?
- A Django URLField has fixed max_length as 200 characters
0š
You might want to add postgres database to the list of database in pgbouncer.ini file, if youāre using pgbouncer with postgresql
- How can I create a partial search filter in Django REST framework?
- What does 'name__iexact' mean in django model filters?
- Supervisorctl always reports error: ERROR (no such file)
- Saving Base64ImageField Type using Django Rest saves it as Raw image. How do I convert it to a normal image
- Django ORM and hitting DB