我正在尝试通过命令在Django框架4.0.4中运行一些自动测试
python manage.py test test.to.run
同样在开始时,它会收到通知:
RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.
,但结果是在没有任何具体解释的情况下出现错误:
...conn = _connect(dsn, connection_factory=connection_factory,**kwasync) psycopg2.OperationalError
The above exception was the direct cause of the following exception:
...
conn = _connect(dsn, connection_factory=connection_factory,
**kwasync) django.db.utils.OperationalError
Connected DB是位于本地网络中另一台计算机上的Postgres。
当我通过命令在dev-server上运行app时
python manage.py runserver
一切正常,数据库没有问题。
我尝试在我的机器上创建本地Postgres数据库,并在settings.py中设置到它的连接,python manage.py test
也运行得很好。
1条答案
按热度按时间a7qyws3x1#
有必要在pg_hba.conf中添加到我的计算机的连接