使用 neo4j python 驱动程序无法在 Neo4j 中创建节点

creating nodes in Neo4j using neo4j python driver not working

我在 Neo4j 中创建节点时遇到问题

   path_data = "BPI2000sample.csv"
df = pd.read_csv(path_data)
uri= "bolt://localhost:7687"
driver = GraphDatabase.driver(uri,auth=("neo4j","123456"))
session = driver.session()
def create_contsraint(tx):
    tx.run("use loan1 CREATE CONSTRAINT ON (e:Event) ASSERT e.name IS UNIQUE;")
    tx.run("use loan1 CREATE CONSTRAINT ON (c:Case) ASSERT c.name IS UNIQUE;")
    tx.run("use loan1 CREATE CONSTRAINT ON (r:Resource) ASSERT r.name IS UNIQUE;")

session.write_transaction(create_contsraint)

with session.begin_transaction() as tx:
    for row in df[df.case.unique == cases].iterrows():
         j = j + 1
         msg = tx.run("use loan1  MERGE (c:Case {name: $case})", case= row[0])
         print(msg)
         #msg = tx.run("use loan1  MERGE (c:Case {name: $case})", case=row[0])
        #row = cursor.fetchone()
    tx.success = True  # commit the cypher statements

print("total nodes created:",j)

它写了约束但没有创建节点这里有什么问题?

收到的消息是什么? 我怀疑你不能使用:use loan1来定义数据库,它通常在会话级别设置:

session = driver.session(database="loan1")

然后:

msg = tx.run("MERGE (c:Case {name: $case})", case= row[0])