使用neo4j python驱动程序在Neo4j中创建节点不工作

zd287kbt  于 2022-11-05  发布在  Python
关注(0)|答案(1)|浏览(224)

在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)

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

eqqqjvef

eqqqjvef1#

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

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

然后道:

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

相关问题