2017-09-13 41 views
1

使用V2 py2neo我可以把这个__init__.py设置Neo4j的唯一性约束在py2neo V3

graph.cypher.execute("CREATE CONSTRAINT ON (n:User) ASSERT n.username IS UNIQUE") 

为什么V3 py2neo

graph.run("CREATE CONSTRAINT ON (n:User) ASSERT n.username IS UNIQUE") 

失败,此错误?

TypeError: unbound method run() must be called with Graph instance as first argument (got str instance instead)

+1

你如何声明'graph'变量? –

+0

哇!你从错误信息中发现了我的错字...我忘了图中的括号= Graph()你怎么做到的? – user1613312

+1

我想你回答了我的问题,但我不能评论你的评分? – user1613312

回答

0

你应该声明变量是这样的:

>>> graph = Graph() 

,而不是(不带支架):

>>> graph = Graph 

此外,作为备选的graph.run()方法,你可以使用graph.schema.create_uniqueness_constraint()方法,如下所示:

>>> graph.schema.create_uniqueness_constraint("User", "username")