I have several classes with the same relationship. For example:
class Foo(db.Model):
__tablename__ = 'foo'
foonr = Column('foonr', Integer, primary_key=True)
bar= Column('bar_code',String, ForeignKey('bar.bar_code'))
bar_rel = relationship('Foo', back_populates='foo_rel')
class Bar(db.Model):
__tablename__ = 'bar'
code = Column('bar_code', String, primary_key=True)
foo_rel = relationship('Foo', uselist=False, back_populates=' bar_rel')
This is almost a copy-paste from: http://docs.sqlalchemy.org/en/latest/orm/basic_relationships.html. However when I try to query an unrelated class (not Foo or Bar) in this example, I get following error:
sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship ... - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
Can someone explain this behaviour? Help me solve this problem?
Thanks.