Test database for Django + Heroku. Error creating the test database: permission denied to create database

I'm trying to run the tests for my Django project. I wrote this project some time ago, I had different settings then and tests were passing. Now I changed settings and deployed it on Heroku with Heroku Postgres database. Everything works fine already except I can't run tests. I've tried many different settings and nothing worked. Most of the time I'm getting this error: permission denied to create database

My last setting is following the instruction from this article on medium Basically I have added 2nd Heroku Postgres database, add settings like below (but with valid variables of my heroku databases):

if 'test' in sys.argv:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'd7osdssadag0ugv5',
            'USER': 'lhwwasadqlgjra',
            'PASSWORD': '1524f48a2ce41177c4ssdadasd3a11680b735302d14979d312ff36',
            'HOST': 'ec2-54-75-2326-118.eu-west-1.compute.amazonaws.com',
            'PORT': 5432,
            'TEST': {
                'NAME': 'd7osdssadag0ugv5', 
            }
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'd7hasadas9hqts5',
            'USER': 'nybkduadsdgqot',
            'PASSWORD': 'bb535b9cdsfsdfdsfdsfac54851f267444dd8cc230b2a786ab9f446',
            'HOST': 'ec2-54-247-132-38.eu-west-1.compute.amazonaws.com',
            'PORT': 5432,
            'TEST': {
                'NAME': 'd7hasadas9hqts5',
            }
        }
    }

Then run python manage.py test --keepdb in my venv. Then I get an error:

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 first PostgreSQL database instead.
  RuntimeWarning
Got an error creating the test database: permission denied to create database

I have also tried what is advised in this article

Do you have any ideas what I could do about this error? I don't know Django well. I play with it from time to time.

I'm using: Python 3.6.9, Django 3.0.3, Heroku Postgresql Hobby Dev

EDIT:

I'm not sure if this is now an issue with my settings DATABASES. Now when I commented out all my settings concerning DATABASES and I run python manage.py runserver my development server starts as normal and I have access to a database I set before (even after restarting a computer). This looks like actual settings don't have effect (??) Any thoughts?

Django version 3.0.3, using settings 'forumproject.settings'
Starting development server at http://127.0.0.1:8000/

Ok, I found out what it was. My database settings were not taken into account, even I had DEBUG=True because I had this line on the end of the settings:

# Activate Django-Heroku.
django_heroku.settings(locals())

After commenting this out the error permission denied to create database goes away and I can run tests with

python manage.py test --keepdb

I'm surprised how always posting a question on stack overflow help me to find answer immediately after. I was running in circles

Back to Top