I have a database model where I need a one-to-many relationship and two one-to-one relationships. Here is the model I made, but it throws errors
class Page(Base): __tablename__ = 'pages' id = Column(Integer, primary_key=True) title = Column(String(100), nullable=False) content = Column(Text, nullable=False) parent_id = Column(Integer, ForeignKey("pages.id"), nullable=True) children = relationship("Page", backref=backref("parent", remote_side=id)) next_id = Column(Integer, ForeignKey("pages.id"), nullable=True) next = relationship("Page", backref=backref("prev", remote_side=id, uselist=False)) prev_id = Column(Integer, ForeignKey("pages.id"), nullable=True) prev = relationship("Page", backref=backref("next", remote_side=id, uselist=False)) def __init__(self, title, content, parent_id=None, next_id=None, prev_id=None): self.title = title self.content = content self.parent_id = parent_id self.next_id = next_id self.prev_id = prev_id def __repr__(self): return '<Page "%r">' % self.title
I get the following error when I try to do something in the database
ArgumentError: Could not determine join condition between parent/child tables on relationship Page.children. Specify a 'primaryjoin' expression. If 'secondary' is present, 'secondaryjoin' is needed as well.
What is really strange is that it worked without the following and previous columns. Does anyone know what happened?
Tom brunoli
source share