I'm new at using sqlalchemy. How do I get rid of a circular dependency error for the tables shown below. Basically my goal is to create A question table with a one to one relationship "best answer" to answer and a one to many relationship "possible_answers" as well.
class Answer(Base):
__tablename__ = 'answers'
id = Column(Integer, primary_key=True)
text = Column(String)
question_id = Column(Integer, ForeignKey('questions.id'))
def __init__(self, text, question_id):
self.text = text
def __repr__(self):
return "<Answer '%s'>" % self.text
class Question(Base):
__tablename__ = 'questions'
id = Column(Integer, primary_key=True)
text = Column(String)
picture = Column(String)
depth = Column(Integer)
amount_of_tasks = Column(Integer)
voting_threshold = Column(Integer)
best_answer_id = Column(Integer, ForeignKey('answers.id'), nullable=True)
possible_answers = relationship("Answer", post_update=True, primaryjoin = id==Answer.question_id)
def __init__(self, text, picture, depth, amount_of_tasks):
self.text = text
self.picture = picture
self.depth = depth
self.amount_of_tasks = amount_of_tasks
def __repr__(self):
return "<Question, '%s', '%s', '%s', '%s'>" % (self.text, self.picture, self.depth, self.amount_of_tasks)
def __repr__(self):
return "<Answer '%s'>" % self.text
This is the error message: CircularDependencyError: Circular dependency detected. Cycles: