今天碰到一个棘手的问题,一个接口需要同时查询两个 db 的两个表,但其中一个表,sqlalchemy 查找的 db 是另外一个,导致查询找不到该表
model 代码如下
class BusinessGroup(db.Model):
__bind_key__ = 'amp'
__tablename__ = 'business_group'
business_group_id = Column(db.BigInteger, primary_key=True)
class DeployJob(Base):
__tablename__ = 'deploy_job'
id = Column(BIGINT(20), primary_key=True)
数据库连接:
SQLALCHEMY_BINDS = {'amp': 'mysql+pymysql://{user}:{passwd}@{host}:{port}/{db}'.format(**AMP_MYSQL_CFG)}
查询的接口代码
def getDpJobList():
try:
deploy_jobs_basic = db.session.query(DeployJob.id,
BusinessGroup.dept_id)
得到的错误:
(pymysql.err.ProgrammingError) (1146, "Table 'monitor.deploy_job' doesn't exist")
不知道有知道该问题所在的小伙伴没?求指导。 多谢