Django应用程序在Travis CI中失败:服务器未在localhost上运行

时间:2015-05-26 07:59:01

标签: django postgresql travis-ci

我正在使用Postgres数据库在Travis CI中测试一个示例Django应用程序。我为在我的开发环境中成功通过的模型编写了一些基本测试。当我将代码推送到Travis时,会发生以下错误:

travis link:https://travis-ci.org/Navajyoth/django-travis/jobs/64052563

github链接:https://github.com/Navajyoth/django-travis

Traceback (most recent call last):

File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/test/runner.py", line 210, in run_tests
old_config = self.setup_databases()
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/test/runner.py", line 166, in setup_databases
**kwargs
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/test/runner.py", line 370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 354, in create_test_db
self._create_test_db(verbosity, autoclobber, keepdb)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 447, in _create_test_db
with self._nodb_connection.cursor() as cursor:
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/base/base.py", line 164, in cursor
cursor = self.make_cursor(self._cursor())
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/base/base.py", line 135, in _cursor
self.ensure_connection()
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/base/base.py", line 119, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 172, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused

Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

The command "python manage.py test apps.account --settings=settings.dev" exited with 1.

Done. Your build exited with 1.

2 个答案:

答案 0 :(得分:2)

上述问题的主要问题。

(1)PostgreSQL版本不受支持 (2)从PostgreSQL插件中删除补丁版本。

解决了问题

答案 1 :(得分:-2)

构建失败,因为您使用postgres作为数据库后端来测试您的应用程序。回溯显示psycopg2无法在localhost上连接:

File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect 
conn = _connect(dsn, connection_factory=connection_factory,async=async)
django.db.utils.OperationalError: could not connect to server:Connection refused
Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
could not connect to server: Connection refused`

您应该使用sqlite作为db后端或指定正确的数据库连接 您settings.dev中的参数。参考https://docs.djangoproject.com/en/1.8/topics/testing/overview/#the-test-database