如何将外键设置为 sqlalchemy 中的一列?

问题描述

class ReportModel(db.Model):
    __tablename__ = "reports"

    id = Column(SmallInteger().with_variant(Integer,"sqlite"),primary_key=True)
    ref_id = Column(
        BigInteger,ForeignKey([PostModel.id,CommentModel.id],nullable=False)
    )
    type = Column(String(20),nullable=False)


    post = relationship("PostModel",backref="post")
    comment = relationship("CommentModel",backref="comment")

有帖子、评论表。我想让 ref_id 一次引用 post.id 和 comment.id。 是否有可能?以及如何制作? 谢谢你!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)