1

Using v2 py2neo I could put this in __init__.py

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

Why does v3 py2neo

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

fail with this error?

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

Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
user1613312
  • 374
  • 2
  • 15

1 Answers1

0

You should declare the graph variable this way:

>>> graph = Graph()

instead of (without the brackets):

>>> graph = Graph

Also, alternatively to the graph.run() method you can use the graph.schema.create_uniqueness_constraint() method, like this:

>>> graph.schema.create_uniqueness_constraint("User", "username")
Bruno Peres
  • 15,845
  • 5
  • 53
  • 89