使用py2neo==4.3.0从mysql读取数据转存到neo4j=3.5.5,节点不同步的问题
发布于 3 个月前 作者 jiangguang 363 次浏览 来自 问答

encoding:utf-8

from models import TStudentGradeCourse from config import graph,nodeMatcher,relationshipMatcher from py2neo import Node,Relationship from flask import Flask

app = Flask(name)

stu_grade_courses=TStudentGradeCourse.query.all()

for res in stu_grade_courses:

stuNode=nodeMatcher.match("Student",name=res.name).first()
gradeNode=nodeMatcher.match("Grade",name=res.grade).first()

if stuNode==None:
    print("创建学生节点"+res.name)
    sutNode=Node("Student",name=res.name)
    graph.create(sutNode)

if gradeNode==None:
    print("创建班级节点"+res.grade)
    gradeNode=Node("Grade",name=res.grade)
    graph.create(gradeNode)

if relationshipMatcher.match(nodes=(stuNode,gradeNode),r_type="belong").first() == None:
    print(res.name,"-->",res.grade)
    graph.create(Relationship(stuNode, "belong", gradeNode))

courses=res.courses.split(",",-1)
for course in courses:
    courseNode=nodeMatcher.match("Course",name=course).first()

    if courseNode==None:
        print("创建课程节点"+course)
        courseNode=Node("Course",name=course)
        graph.create(courseNode)

    if relationshipMatcher.match(nodes=(stuNode,courseNode),r_type="choose").first()==None:
        print(res.name+"-->"+course)
        graph.create(Relationship(stuNode,"choose",courseNode))

报错的信息如下: result = self._query(query) 创建学生节点Tom 创建班级节点软件工程 Traceback (most recent call last): File “D:/python/neo4jtest/ope.py”, line 29, in <module> graph.create(Relationship(stuNode, “belong”, gradeNode)) File “D:\setup\virtualenv\neo4j35\lib\site-packages\py2neo\database.py”, line 363, in create tx.create(subgraph) File “D:\setup\virtualenv\neo4j35\lib\site-packages\py2neo\database.py”, line 906, in create create(self) File “D:\setup\virtualenv\neo4j35\lib\site-packages\py2neo\data.py”, line 609, in db_create create_subgraph(tx, self) File “D:\setup\virtualenv\neo4j35\lib\site-packages\py2neo\internal\operations.py”, line 134, in create_subgraph for labels, nodes in _node_create_dict(n for n in subgraph.nodes if n.graph is None).items(): File “D:\setup\virtualenv\neo4j35\lib\site-packages\py2neo\internal\operations.py”, line 44, in _node_create_dict for node in nodes: File “D:\setup\virtualenv\neo4j35\lib\site-packages\py2neo\internal\operations.py”, line 134, in <genexpr>

** for labels, nodes in _node_create_dict(n for n in subgraph.nodes if n.graph is None).items():* AttributeError: ‘NoneType’ object has no attribute ‘graph’*** Tom --> 软件工程

errorInfo.png

回到顶部