sqlalchemy multiple foreign keys to same table

后端 未结 1 1734
暖寄归人
暖寄归人 2021-01-06 14:35

I have a postgres database that looks something like this:

      Table \"public.entities\"
    Column     |            Type             |                   M         


        
相关标签:
1条回答
  • 2021-01-06 15:11

    It's not completely clear what exactly is causing the problem since you omitted the most important part -- code that throws that exception but if adding relationship properties to class PostModel throws that try to add foreign_keys parameter to relationship call as the following:

    class PostModel(...):
        # ...
        subject1_id = Column(db.Column(db.BigInteger, db.ForeignKey(EntitiesModel.id), nullable=False)
        subject2_id = Column(db.Column(db.BigInteger, db.ForeignKey(EntitiesModel.id), nullable=False)
        subject1 = relationship(EntitiesModel, foreign_keys=subject1_id)
        subject2 = relationship(EntitiesModel, foreign_keys=subject2_id)
    
    0 讨论(0)
提交回复
热议问题