作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在settings.py中的数据库设置如下
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'dbname',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': '',
'PORT':'8081',
}
}
但是在运行 python manage.py migrate 时我收到错误 django.db.utils.OperationalError:无法连接到服务器:没有这样的文件或目录
Traceback (most recent call last):
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/backends/base/base.py", line 119, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.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/.s.PGSQL.8081"?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/migrations/loader.py", line 182, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/backends/base/base.py", line 162, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/backends/base/base.py", line 135, in _cursor
self.ensure_connection()
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
raise value.with_traceback(tb)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
self.connect()
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/backends/base/base.py", line 119, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/vivekpradhan/joker/basket/local/lib/python3.4/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: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.8081"?
任何帮助都会有所帮助提前致谢我正在开发 ubantu 操作系统。
最佳答案
看起来 PostgreSQL 根本没有运行。尝试运行
sudo service postgresql start
关于python - django.db.utils.OperationalError : could not connect to server: No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32805224/
我是一名优秀的程序员,十分优秀!