Creating test database for alias 'postgres'...Got an error creating the test database: permission

xiaoxiao2021-02-28  106

django python manage.py test 出错, 错误提示如下:

Creating test database for alias 'postgres'... 

Got an error creating the test database: permission

Django settings 设置如下:

DBNAME = 'multi_test' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), }, 'mysql': { 'ENGINE': 'django.db.backends.mysql', 'NAME': DBNAME, 'USER': 'root', 'PASSWORD': 'xxx', 'HOST': '127.0.0.1', 'PORT': 3306, 'OPTIONS': { 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'", }, }, 'postgres': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': DBNAME, 'USER': 'root', 'PASSWORD': 'xxx', 'HOST': '127.0.0.1', 'PORT': 5432, }, }

python manage.py migrate 可以正常运行

解决途径:

在postgresql数据库中给root用户(root为settings中的'postgres'对应的'USER')增加createdb的权限

wenjie@digi007:~/study/dbtest/multi_dbs$ su - postgres 密码: postgres@digi007:~$ psql psql (9.6.2) Type "help" for help. postgres=# alter user root createdb; 在重新 运行test就不再报错 了。

转载请注明原文地址: https://www.6miu.com/read-62819.html

最新回复(0)