谢谢大家。代码如下,总是会提示这个错误:sqlalchemy.exc.NoForeignKeysError:Couldnotdeterminejoinconditionbetweenparent/childtablesonrelationshipProblem.tags-therearenoforeignkeyslinkingthesetablesviasecondarytable'problem_tags'.EnsurethatreferencingcolumnsareassociatedwithaForeignKeyorForeignKeyConstraint,orspecify'primaryjoin'and'secondaryjoin'expressions.tags_table=db.Table('problem_tags',db.Column('problem_id',db.Integer,db.ForeignKey('problem.id')),db.Column('tag_id',db.Integer,db.ForeignKey('problemtag.id')))classProblemTag(db.Model):id=db.Column(db.Integer,primary_key=True)name=db.Column(db.String(80))problems=db.relationship('Problem',secondary=tags_table,backref=db.backref('tags',lazy='dynamic'))def__init__(self,name):self.name=namedef__repr__(self):return""%self.nameclassProblem(db.Model):id=db.Column(db.Integer,primary_key=True)title=db.Column(db.String(80))tags=db.relationship('ProblemTag',secondary=tags_table,backref=db.backref('problems',lazy='dynamic'))def__init__(self,title,tags):self.title=titleself.tags=tagsdef__repr__(self):return""%self.title
添加回答
举报
0/150
提交
取消