0 votes
1 view
in SQL by (20.3k points)

When I try to test any app with the command (I noticed it when I tried to deploy myproject using fabric, which uses this command):

python manage.py test appname

I get this error:

Creating test database for alias 'default'...

Got an error creating the test database: permission denied to create database

Type 'yes' if you would like to try deleting the test database 'test_finance', or 'no' to cancel

syncdb command seems to work. My database settings in settings.py:

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.

        'NAME': 'finance',                      # Or path to database file if using sqlite3.

        'USER': 'django',                      # Not used with sqlite3.

        'PASSWORD': 'mydb123',                  # Not used with sqlite3.

        'HOST': '127.0.0.1',                      # Set to empty string for localhost. Not used with sqlite3.

        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.

    }

}

1 Answer

0 votes
by (40.3k points)

In your case i.e.  test_finance, when Django runs the test suite, it creates the new database. But, the postgres user with username django does not have permission to create the database, hence the error message occurs.

When we run migrate or syncdb, Django will not try to create the finance database, therefore you will not get any errors.

By running the following command in the postgres shell as a superuser, you can add the createdb permission to the django user.

=> ALTER USER django CREATEDB;

Note The username which is used in the ALTER USER <username> CREATEDB; command should be matched to the database user in your Django settings files. 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...