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

后端 未结 9 929
甜味超标
甜味超标 2020-12-22 16:53

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

python manage.py test appname
         


        
9条回答
  •  独厮守ぢ
    2020-12-22 17:15

    When Django runs the test suite, it creates a new database, in your case test_finance. The postgres user with username django does not have permission to create a database, hence the error message.

    When you run migrate or syncdb, Django does not try to create the finance database, so you don't get any errors.

    You can add the createdb permission to the django user by running the following command in the postgres shell as a superuser (hat tip to this stack overflow answer).

    => ALTER USER django CREATEDB;
    

    Note: The username used in the ALTER USER CREATEDB; command needs to match the database user in your Django settings files. In this case, the original poster, had the user as django the above answer.

提交回复
热议问题