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 Commented May 11, 2016 at 4:50
  • Please check in the test settings if you are using the same myuser. Commented 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? Commented 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. Commented May 11, 2016 at 5:08

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.