为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

呼唤远方 2019-02-24 18:41:33
谢谢大家。 代码如下,总是会提示这个错误: sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship Problem.tags - there are no foreign keys linking these tables via secondary table 'problem_tags'. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify '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')) ) class ProblemTag(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 "<Tag %r>" % self.name class Problem(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 "<Problem %r>" % self.title
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 1235 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信