簡體   English   中英

Travis:“創建測試數據庫時出錯:創建數據庫的權限被拒絕”

[英]Travis: “Got an error creating the test database: permission denied to create database”

這是我的travis.yml文件:

language: python
python:
  - "2.7"
addons:
  postgresql: "9.3"
env:
  - SECRET_KEY=test DB_NAME=dbtest DB_USER=test DB_PASS=test
before_install:
  - export DJANGO_SETTINGS_MODULE=settings.local
  - export PYTHONPATH=$HOME/builds/me/myrepo
install:
 - pip install -r requirements.txt
before_script:
 - psql -U postgres -c 'CREATE DATABASE dbtest;'
 - psql -U postgres -c "CREATE EXTENSION postgis" -d dbtest
 - psql -U postgres -c "CREATE EXTENSION postgis_topology" -d dbtest
 - psql -U postgres -c "CREATE USER test WITH PASSWORD 'test';"
 - psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE dbtest to test;"
 - cd myapp && python manage.py migrate
script:
 - python manage.py test

但是當我部署repo並運行Travis時,它會輸出以下錯誤:

10.96s$ pip install -r requirements.txt
0.24s$ psql -U postgres -c 'CREATE DATABASE dbtest;'
0.77s$ psql -U postgres -c "CREATE EXTENSION postgis" -d dbtest
0.09s$ psql -U postgres -c "CREATE EXTENSION postgis_topology" -d dbtest
0.01s$ psql -U postgres -c "CREATE USER test WITH PASSWORD 'test';"
0.01s$ psql -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE dbtest to test;"
1.89s$ cd myapp && python manage.py migrate
$ python manage.py test
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_dbtest', or 'no' to cancel: 

我嘗試添加psql -U postgres -c "ALTER USER django CREATEDB;" 這樣django用戶就有權創建數據庫,但失敗了:

ERROR:  role "django" does not exist
The command "psql -U postgres -c "ALTER USER django CREATEDB;"" failed and exited with 1 during .

答案:我必須讓測試用戶成為超級用戶:

CREATE USER test WITH PASSWORD 'test'; 

然后授予用戶創建數據庫的權限:

ALTER USER test CREATEDB;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM