我遵循了 Djangogirls 教程,通常教程要求您在 pythonanywhere
上创建一个数据库。这在使用 sqlite3
时通常可以顺利运行,但是这次我使用 postgresql
并且在运行 migrate
命令时出现以下错误在控制台中:
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql
这到底是什么意思?
使用 python 3.5.1
django 1.9.8
postgresql 9.4
谢谢
好的,在阅读更多内容后,简而言之,这是我的问题。
我在本地运行 postgresql。然后我将 wbapp 部署到 pythonanywhere 上。在那里,我尝试通过运行 migrate 创建数据库,这导致了上述错误。
从那时起,我意识到我必须设置 postgresql 才能在 pythonanywhere 上运行。我按照说明去做了,但我不明白的是我现在必须从头开始创建数据库吗?如果是这种情况,我的本地数据库中的所有表等会发生什么情况?
最佳答案
澄清一下,您不应该尝试连接到本地 postgres。相反,您应该在 pythonanywhere 上设置 postgres,并确保您的 django settings.py 将数据库地址和端口指向 pythonanywhere 数据库。这不是您运行代码的控制台/webapp 服务器的本地。相反,转到 pythonanywhere 数据库选项卡并查看提供给您的地址/端口。
关于python - Postgresql:将本地数据库迁移到 PythonAnywhere 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38686955/