SQLAlchemy外键找不到表

2024-01-29

当我尝试实例化时出现此错误ConsumerAdvice class.

Foreign key associated with column 'tbConsumerAdvice.ConsumerAdviceCategory_ID' 
could not find table 'tbConsumerAdviceCategories' with which to generate a
foreign key to target column 'ID_ConsumerAdviceCategories'
class ConsumerAdviceCategory(Base):
    __tablename__ = 'tbConsumerAdviceCategories'
    __table_args__ = {'schema':'dbo'}
    ID_ConsumerAdviceCategories = Column(INTEGER, Sequence('idcac'),\
            primary_key=True)
    Name = Column(VARCHAR(50), nullable=False)

    def __init__(self,Name):
        self.Name = Name

    def __repr__(self):
        return "< ConsumerAdviceCategory ('%s') >" % self.Name

class ConsumerAdvice(Base):
    __tablename__ = 'tbConsumerAdvice'
    __table_args__ = {'schema':'dbo'}
    ID_ConsumerAdvice = Column(INTEGER, Sequence('idconsumeradvice'),\
            primary_key=True)
    ConsumerAdviceCategory_ID = Column(INTEGER,\
            ForeignKey('tbConsumerAdviceCategories.ID_ConsumerAdviceCategories'))
    Name = Column(VARCHAR(50), nullable=False)
    Category_SubID = Column(INTEGER)

    ConsumerAdviceCategory = relationship("ConsumerAdviceCategory",\
            backref=backref('ConsumerAdvices'))

    def __init__(self,Name):
        self.Name = Name

    def __repr__(self):
        return "< ConsumerAdvice ('%s') >" % self.Name

定义包含架构的 FK:dbo.tbConsumerAdviceCategories.ID_ConsumerAdviceCategories

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SQLAlchemy外键找不到表 的相关文章

随机推荐