SQLAlchemy ForeignKey can't find table

て烟熏妆下的殇ゞ 提交于 2019-12-05 02:06:26

Define the FK including schema: dbo.tbConsumerAdviceCategories.ID_ConsumerAdviceCategories

Shahaf

I also hit this error. In my case the root cause was that I attempted to define different sqlalchemy base classes:

Base1 = declarative_base(cls=MyBase1)
Base1.query = db_session.query_property()

Base2 = declarative_base(cls=MyBase2)
Base2.query = db_session.query_property()

I had a ForeignKey relationship from one class that derives from Base1 to another class that derives from Base2. This didn't work -- I got a similar NoReferencedTableError. Apparently classes must derive from the same Base class in order to know about each other.

Hope this helps someone.

Winston

That didn't solve my problem, I had to use.

ConsumerAdviceCategory_ID = Column(INTEGER,
            ForeignKey('tbConsumerAdviceCategories.ID_ConsumerAdviceCategories',  
            schema='dbo'))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!