4

I've created a user, and given it the required privileges - i.e.

ALTER USER myuser CREATEDB

I can log in to psql as this user and create a database, however when I try to run django tests, I get "permission denied":

$ ./manage.py test
Creating test database for alias 'default'...
Got an error creating the test database: permission denied to create database

I have no such issues in another django project running off the same postgres instance, so something about my django project must be causing the error. The python and django versions are identical.

Any ideas?

4
  • 1
    You should be myuser when running tests. Maybe you should update DATABASES setting in settings.py for unit tests May 11, 2016 at 4:50
  • Please check in the test settings if you are using the same myuser.
    – AKS
    May 11, 2016 at 4:54
  • There are no test settings, in fact there aren't even any tests as yet, but I thought django just used the default user for tests anyway? How do I tell which user my tests are using?
    – Greg
    May 11, 2016 at 4:58
  • I'm moron. It was a local settings file and the user in that file didn't have the required permission.
    – Greg
    May 11, 2016 at 5:08
3

Following steps may help you ,

CREATE DATABASE test_database;
CREATE USER tester WITH PASSWORD 'test_password';
GRANT ALL PRIVILEGES ON DATABASE "test_database" to tester;
1

Make sure you're actually running as the user you think you are - for example, check any local settings files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.