【发布时间】:2011-09-19 23:42:07
【问题描述】:
SQLAlchemy 中有没有办法进行跨数据库连接。具体来说,这是我的用例:
架构
- db1.entity1
- entity1_id:主键
- entity2_id:db2.entity2.entity2_id 的外键
- db2.entity2
- entity2_id:主键
型号
我正在为模型使用声明式风格。
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)
现在,正如预期的那样,我对 Entity1 的查询失败,并显示 MySQL 错误消息说找不到表 entity2。我为__tablename__ 尝试了许多不同的组合,但没有成功。所以我想知道在 SQLAlchemy 中是否有可能。
【问题讨论】:
标签: python sqlalchemy flask-sqlalchemy