我正在为运行测试设置Django项目。 但是我遇到了以下错误:
Got an error creating the test database: permission denied to copy database "template_postgis"
注意: 我的默认应用程序数据库可以正常工作。问题出现在运行测试时。完整的堆栈跟踪如下:
moin@moin-pc:~/workspace/mozio$ python manage.py test --verbosity=3
nosetests --verbosity=3
nose.config: INFO: Ignoring files matching ['^\\.', '^_', '^setup\\.py$']
Creating test database for alias 'default' ('test_my_db')...
Got an error creating the test database: permission denied to copy database "template_postgis"
Type 'yes' if you would like to try deleting the test database 'test_mozio_db_test', or 'no' to cancel: yes
Destroying old test database 'default'...
Got an error recreating the test database: must be owner of database test_mozio_db_test
以下��
setting.py
的数据库配置:POSTGIS_VERSION = (2, 2, 2)
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'my_db',
'USER': 'my_user',
'PASSWORD': 'my_pass',
'HOST': '<HOST_IP',
'PORT': '',
'TEST': {
'NAME': 'test_my_db',
},
}
}
需要帮忙吗?以下是我尝试过的步骤:
Grant create DB access to user:
ALTER USER my_user CREATEDB;
Grant all privileges to user for
test_my_db
database:GRANT ALL PRIVILEGES ON DATABASE test_mozio_db_test to mozio;
编辑: 在解决了上述问题之后,我还遇到了以下错误:
django.db.utils.ProgrammingError: type "geometry" does not exist
LINE 5: "polygon" geometry(POLYGON,4326) NOT NULL,
我更新了答案,修复了两个问题。