0

vagrant ボックスに、postgres を介してインストールしapt-get install python-psycopg2ました。正常にインポートをテストしました。

$ python
Python 2.6.5 (r265:79063, Oct  1 2012, 22:04:36) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> exit()

Django 設定ファイル:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/vagrant/v-root/projects/tdg/tdg/mydata.db',                      # Or path to database file if using sqlite3.
        'USER': 'username',                      # Not used with sqlite3.
        'PASSWORD': 'password',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

新しい vagrant ボックスで postgres_psycopg2 が見つからないという問題があります。

$ python manage.py shell
Python 2.6.5 (r265:79063, Oct  1 2012, 22:04:36) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.db import connection
>>> cursor = connection.cursor()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py", line 306, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
    self.connection = Database.connect(**conn_params)
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.5432"?

>>> 

を実行しましたが、netstat —listenポート 5432 がリッスンしていませんでした。22 (SSH) と 8000 (Django アプリ) のみがリッスンしています。

4

1 に答える 1

1

postgres を完全にはインストールしていません。postgres の Python クライアントである psycopg2 をインストールしただけです。次のように postgres をインストールして実行する必要があります。

apt-get install postgresql
/etc/init.d/postgresql start

(おそらく、それにログインして、プロジェクトが対話するためのデータベースを自分で作成する必要もあります)

于 2013-01-30T22:31:24.980 に答える