0

我正在开发使用 neo4j 数据库的 django 项目。这是我的 models.py 文件的一部分:

模型.py:

from neo4django.db import models

class User(models.NodeModel):

    firstName = models.StringProperty(max_length=20)
    lastName = models.StringProperty(max_length=20)
    password = models.StringProperty(max_length=50)
    email = models.EmailProperty()
    status = models.BooleanProperty()
    BirthDate = models.DateProperty()
    gender = models.BooleanProperty()

我遵循neo4django 文档并更改 settings.py 文件:setting.py:

DATABASES = {
    'default': {
         'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
         'NAME': 'mylifetime',                      # Or path to database file if using sqlite3.
         # The following settings are not used with sqlite3:
         'USER': 'root',
         'PASSWORD': 'password',
         'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

NEO4J_DATABASES = {
    'default' : {
        'HOST':'localhost',
        'PORT':7474,
        'ENDPOINT':'/db/data'
    }
}

但是当我运行 shell 以在 db 中创建一些节点时,我收到连接被拒绝错误:

mojtaba@mojtaba-desktop:~/Documents/mylifetime$ python manage.py shell
Python 2.7.3 (default, Aug  1 2012, 05:16:07) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from social.models import *
>>> test = User.objects.create(firstName = 'peter' )
    Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/models/manager.py", line 43, in create
    return self.get_query_set().create(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/models/query.py", line 1296, in create
    return super(NodeQuerySet, self).create(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 402, in create
    obj.save(force_insert=True, using=self.db)
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/models/base.py", line 315, in save
    return super(NodeModel, self).save(using=using, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 546, in save
    force_update=force_update, update_fields=update_fields)
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/models/base.py", line 331, in save_base
    self._save_neo4j_node(using)
  File "<string>", line 2, in _save_neo4j_node
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/models/base.py", line 93, in trans_method
    len(connections[args[0].using]._transactions) < 1:
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/utils.py", line 494, in __getitem__
    conn = Client('http://%s:%d/db/data' % (db['HOST'], db['PORT']), **db['OPTIONS'])
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/neo4jclient.py", line 30, in __init__
    super(EnhancedGraphDatabase, self).__init__(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/neo4jrestclient-1.9.0-py2.7.egg/neo4jrestclient/client.py", line 84, in __init__
    response, content = Request(**self._auth).get(self.url)
  File "/usr/local/lib/python2.7/dist-packages/neo4jrestclient-1.9.0-py2.7.egg/neo4jrestclient/request.py", line 144, in get
    return self._request('GET', url, headers=headers)
  File "/usr/local/lib/python2.7/dist-packages/neo4django-0.1.8-py2.7.egg/neo4django/db/__init__.py", line 61, in _request
    headers)
  File "/usr/local/lib/python2.7/dist-packages/neo4jrestclient-1.9.0-py2.7.egg/neo4jrestclient/request.py", line 306, in _request
    body=body)
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 1444, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 1196, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 1132, in _conn_request
    conn.connect()
  File "/usr/lib/python2.7/dist-packages/httplib2/__init__.py", line 798, in connect
    raise socket.error, msg
error: [Errno 111] Connection refused
4

1 回答 1

0

似乎是连接错误。你确定 Neo 服务器正在监听 localhost 的 7474 端口吗?

既然是休息,请尝试在 localhost:7474 上使用您的浏览器

于 2013-08-08T16:58:03.703 回答