【发布时间】:2020-10-31 08:47:20
【问题描述】:
在尝试创建唯一约束或简单合并语句时收到AttributeError 和ValueError。然而,约束/节点是在 Neo4j 数据库中创建的。
我正在使用py2neo==2020.0.0
## Create uniqueness constraint (with name)
cypher_str = "CREATE CONSTRAINT UniqueAirportNameConstraint ON (a:Airport) ASSERT a.name IS UNIQUE"
graph.run(cypher_str)
## Merging
params = [{'airline': '3K', 'seats': 500, 'departure': '0915'}]
q = """
UNWIND $data AS data
MERGE (s:Schedule)
"""
graph.run(q, { "data": params })
收到错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~/miniconda3/envs/neo4j/lib/python3.7/site-packages/py2neo/database/work.py in __init__(self, records, keys)
889 try:
--> 890 k = records.keys()
891 except AttributeError:
AttributeError: 'list' object has no attribute 'keys'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
~/miniconda3/envs/neo4j/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
700 type_pprinters=self.type_printers,
701 deferred_pprinters=self.deferred_printers)
--> 702 printer.pretty(obj)
703 printer.flush()
704 return stream.getvalue()
~/miniconda3/envs/neo4j/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
392 if cls is not object \
393 and callable(cls.__dict__.get('__repr__')):
--> 394 return _repr_pprint(obj, self, cycle)
395
396 return _default_pprint(obj, self, cycle)
~/miniconda3/envs/neo4j/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
698 """A pprint that just redirects to the normal repr function."""
699 # Find newlines and replace them with p.break_()
--> 700 output = repr(obj)
701 lines = output.splitlines()
702 with p.group():
~/miniconda3/envs/neo4j/lib/python3.7/site-packages/py2neo/database/work.py in __repr__(self)
367
368 def __repr__(self):
--> 369 return repr(self.preview(3))
370
371 def __next__(self):
~/miniconda3/envs/neo4j/lib/python3.7/site-packages/py2neo/database/work.py in preview(self, limit)
497 values = self._hydrant.hydrate(keys, values, entities=self._entities, version=v)
498 records.append(values)
--> 499 return Table(records, keys)
500
501 def evaluate(self, field=0):
~/miniconda3/envs/neo4j/lib/python3.7/site-packages/py2neo/database/work.py in __init__(self, records, keys)
890 k = records.keys()
891 except AttributeError:
--> 892 raise ValueError("Missing keys")
893 width = len(k)
894 t = [set() for _ in range(width)]
ValueError: Missing keys
【问题讨论】:
-
我会推荐 neo4j 驱动程序而不是 py2neo。 Neo4j 直接支持。
标签: neo4j jupyter-notebook py2neo