Search code examples
pythonneo4jexceptionpy2neo

unable to find the correct exception


I use py2neo to insert data from a json. Everything works perfects.

But I was unable to find in the documentation the information related to this exception.

neo4j.exceptions.ConstraintError: Node(0) already exists with label `Documents` and property `itemid` = '994263771'

I was trying with

except py2neo.database.status.ConstraintError

But this only work with py2neo 3.x


Solution

  • You apparently have a uniqueness constraint on the itemid property of the Documents label. Therefore, whenever neo4j detects that you are trying to create a new Documents node with the same itemid value as an existing Documents node, it is throwing an exception indicating a constraint violation.

    You should use the merge method instead of create.