neomodel在保存时给出属性错误

时间:2016-05-18 11:33:50

标签: python neo4j py2neo neomodel

我正在为neo4j运行以下配置:

neo4j - 3.0.0
py2neo - 2.0.8
neomodel - 2.0.2

最后,我尝试运行的代码是:

class User(neomodel.StructuredNode):
    user_id = neomodel.IntegerProperty(unique_index=True, required=True)
    name = neomodel.StringProperty()
    phone_number = neomodel.StringProperty()

user = User(user_id=6, name='Sourabh Dev', phone_number='9711237840').save()

我不明白,为什么我一直收到这个奇怪的错误。我在这里做错了什么,或者我应该使用py2neo而不是neomodel?

我的追溯是:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/local/lib/python3.4/site-packages/neomodel-2.0.2-py3.4.egg/neomodel/signals.py", line 25, in hooked
    val = fn(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/site-packages/neomodel-2.0.2-py3.4.egg/neomodel/core.py", line 159, in save
    self._id = self.create(self.__properties__)[0]._id
  File "/usr/local/lib/python3.4/site-packages/neomodel-2.0.2-py3.4.egg/neomodel/core.py", line 289, in create
    results = db.cypher_query(query, params)
  File "/usr/local/lib/python3.4/site-packages/neomodel-2.0.2-py3.4.egg/neomodel/util.py", line 213, in cypher_query
    results = self._execute_query(query, params)
  File "/usr/local/lib/python3.4/site-packages/neomodel-2.0.2-py3.4.egg/neomodel/util.py", line 207, in _execute_query
    results = self.session.cypher.execute(query, create_params=params)
  File "/usr/local/lib/python3.4/site-packages/py2neo/cypher/core.py", line 136, in execute
    results = tx.commit()
  File "/usr/local/lib/python3.4/site-packages/py2neo/cypher/core.py", line 333, in commit
    return self.post(self.__commit or self.__begin_commit)
  File "/usr/local/lib/python3.4/site-packages/py2neo/cypher/core.py", line 288, in post
    raise self.error_class.hydrate(error)
  File "/usr/local/lib/python3.4/site-packages/py2neo/cypher/error/core.py", line 54, in hydrate
    error_cls = getattr(error_module, title)
AttributeError: 'module' object has no attribute 'TypeError'

1 个答案:

答案 0 :(得分:5)

这里有两点:

  1. 现有的Neomodel不支持Neo4j 3.0

  2. Cypher语法在3.0中已更改,因此错误会增加。

  3. 在2.x中,MATCH n 返回n
                 在3.0中,MATCH (n) RETURN n

    节点n括在大括号中。