SQLite到PostgreSQL问题[wigtail tutorial]

时间:2018-03-02 12:26:03

标签: django wagtail

这是我第一次将我的wagtail应用程序(我为此感到非常自豪:)部署到heroku。我按照本教程(见下面的链接): https://wagtail.io/blog/deploying-wagtail-heroku/

但是我在本教程中遇到了一个问题: 我在sqlite和PostgreSQL之间更改数据库时。

有麻烦:

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 "/tmp/.s.PGSQL.5432"?

我在mac os 10.13.3上。 Python与Anaconda。

我所做的就是:

在此之前,没有安装过postgresql。我没有运行任何postgres服务器(我不知道如何检查它,但我在本教程的第一步卡住了......)。

感谢您的帮助! :)

整个终端回复

    The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 83, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/migrations/executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/migrations/loader.py", line 52, in __init__
    self.build_graph()
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/migrations/loader.py", line 209, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
    self.ensure_schema()
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
    if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 254, in cursor
    return self._cursor()
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 229, in _cursor
    self.ensure_connection()
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
    self.connect()
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
    self.connect()
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/Users/darkbook/anaconda3/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
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 "/tmp/.s.PGSQL.5432"?

2 个答案:

答案 0 :(得分:1)

如果您没有运行任何PostgreSQL服务器,那么错误消息中的建议&#34;服务器是否在本地运行?&#34;非常有帮助! :)

由于您使用的是OS X,我建议使用https://postgresapp.com作为开始使用PostgreSQL的最简单方法。

请注意,虽然有充分的理由在两个地方使用相同的设置,但可以在本地使用SQLite开发项目,并在Heroku上使用PostgreSQL。

答案 1 :(得分:0)

您需要创建Postgres数据库才能连接到它。最简单的方法是使用Postico:https://eggerapps.at/postico/

在Postico中创建数据库(示例数据库名称&#34; mysite&#34;),然后在您的base.py设置中,您可以使用以下内容:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'mysite',
    'USER': '',  # e.g 'postgres'
    'PASSWORD': '',
    'HOST': '',  # Set to empty string for localhost.
    'PORT': '',  # Set to empty string for default.
    'CONN_MAX_AGE': 600,  # number of seconds database connections should persist for
}

}

请勿忘记您需要再次运行迁移才能构建所有表格。因此,从manage.py开始,您需要makemigrations,然后migrate