2017-09-13 101 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")