SQLAlchemy中有没有办法进行跨数据库连接.具体来说,这是我的用例:
架构
模型
我正在为模型使用声明式样式.
class Entity1(Base):
__tablename__ = 'entity1' ## I tried combination of <db>.<table> with no success
entity1_id = Column(Integer, primary_key=True)
entity2_id = Column(Integer, ForeignKey('db2.entity2.entity2_id'))
entity2 = relationship('Entity2')
class Entity2(Base):
__tablename__ = 'entity2' ## I tried combination of <db>.<table> with no success
entity2_id = Column(Integer, primary_key=True)
Run Code Online (Sandbox Code Playgroud)
现在,正如预期的那样,我对Entity1的查询失败,并显示MySQL错误消息,表示找不到表entity2.我尝试了许多不同的组合但__tablename__没有成功.所以我想知道SQLAlchemy是否可行.