I used to call
call apoc.export.json.all("backup.json",{useTypes:true})
to backup my database content on the one hand and now I'm trying to migrate data to another machine on the other hand by exporting to json first and importing it afterwards.
call apoc.import.json("backup.json")
which should be a valid option according to some neo4j developer. However I run into an exception:
Failed to invoke procedure `apoc.import.json`: Caused by: java.lang.RuntimeException: Missing constraint required for import. Execute this query:
CREATE CONSTRAINT FOR (n:MyLabel01) REQUIRE n.neo4jImportId IS UNIQUE;
Even creating this requirement results in more and more errors of that type.
These error occur when I try to migrate my data from an older neo4j version / apoc version to a newer one, but also when I export from neo4j kernel 5.12.0 enterprise with apoc version 5.12.0 according to return apoc.version() and try to import in a fresh database of the same version where I exported the json.
So I tried to find some workaround and found
CALL apoc.load.json("backup.json") yield value
WHERE value.type = "node"
CALL apoc.create.node(value.labels,value.properties)
yield node return node
but I could not figure out how to import the relashionships too.
- Is there (a different) standard way of porting database content to another machine?
- Or is there some option to utilize apoc.load.json("backup.json") and to create nodes and relationships?
Workaround
I wrote a little python script to convert the exported json in to a cypher
CREATEinstruction. It should create the database content as exported previously.If the exported json has additional properties that are not treated by this script, it prints at least a list of "errors" which are just these ignored parts of the json input, so that the user can manually check.