我正在启动一个django项目,在共享的运行程序上使用gitlab的ci/cd,并使用postgres作为数据库。
我有一个奇怪的问题,好像Django正在用用户名“PestGres”创建测试数据库,我找不到一种配置它的设置的方法,并改变它来使用名为“Runter”的角色。这会导致我的ci/cd管道中断。
这是我的
.gitlab-ci.yml
:
image: python:3.6.5
services:
- postgres:latest
variables:
POSTGRES_DB: asdproject
POSTGRES_USER: runner
POSTGRES_PASSWORD: asdpassword
test:
script:
- whoami
- export DATABASE_URL=postgres://postgres:@postgres:5432/asdproject
- export PGPASSWORD=$POSTGRES_PASSWORD
- apt-get update -qy
- apt-get install -y python-dev python-pip
- pip install -r requirements.txt
- python manage.py test - settings=asd.gitlab_runner_settings
还有我的
gitlab_runner_settings.py
文件:
我尝试了许多更改settings.py的方法,这些方法都是在问题中推荐的,但都不起作用。
from asd.with_debug_settings import *
import sys
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'asdproject',
'USER': 'runner',
'PASSWORD': 'asdpassword',
'HOST': 'postgres',
'PORT': '5432',
'TEST': {
'NAME': 'asdtest',
'USER': 'runner'
},
}
}
在gitlab中运行管道脚本时出现的错误是:
---------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Using existing test database for alias 'default'...
System check identified no issues (0 silenced).
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: role "postgres" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/test.py", line 26, in run_from_argv
super().run_from_argv(argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/test.py", line 56, in handle
failures = test_runner.run_tests(test_labels)
File "/usr/local/lib/python3.6/site-packages/django/test/runner.py", line 607, in run_tests
self.teardown_databases(old_config)
File "/usr/local/lib/python3.6/site-packages/django_heroku/core.py", line 41, in teardown_databases
self._wipe_tables(connection)
File "/usr/local/lib/python3.6/site-packages/django_heroku/core.py", line 33, in _wipe_tables
"""
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: role "postgres" does not exist
ERROR: Job failed: exit code 1