How do I refer to a foreign key table twice?

前端 未结 1 1769
孤城傲影
孤城傲影 2021-01-24 21:11

I get the following error:

u\'detail\': u\"One or more mappers failed to initialize - can\'t proceed with initialization of other mappers. Original exc

相关标签:
1条回答
  • 2021-01-24 21:51

    SQLAlchemy is unable to discover the relationship path.

    user_id = Column(ForeignKey('user.id'))
    user = relationship(User, backref=backref('votes_user'))
    responder_id = Column(ForeignKey('user.id'))
    responder = relationship(User, backref=backref('votes_responder'))
    

    Do the responder relationship must join using responder_id or user_id? I know it is obvious to us, but SQLAlchemy don't consider column names here. You can rename responder_id as foobar and it'll make no difference.

    Define the foreign keys you want to use for each relationship.

    user = relationship(User, foreign_keys=[user_id], backref=backref('votes_user'))
    responder = relationship(User, foreign_keys=[responder_id], backref=backref('votes_responder'))
    
    0 讨论(0)
提交回复
热议问题