猿问

使用Flask-SQLAlchemy时多对多遇到问题,请帮忙看看

谢谢大家。
代码如下,总是会提示这个错误:
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=name
def__repr__(self):
return""%self.name
classProblem(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=title
self.tags=tags
def__repr__(self):
return""%self.title
拉莫斯之舞
浏览 316回答 2
2回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答