sqlalchemy - 无法为映射表

时间:2015-10-02 20:40:38

标签: python sqlalchemy

我正在使用sqlalchemy来反映没有定义外键的现有数据库。给出以下示例:

engine = sqlalchemy.create_engine(...)
Base = declarative_base()
Base.metadata.reflect(engine)

class A(Base):
    __table__ = Base.metadata.tables['A']


class B(Base):
    __table__ = Base.metadata.tables['B']

class C(Base):
    __table__ = sqlalchemy.outerjoin(A, B, onclause=A.foo==B.foo)

如何限制C中使用的字段?

我尝试过设置:

__mapper_args__ = {
    'include_properties': ['foo', 'bar']
}

但是得到错误

Mapper Mapper|C|Join object on Join object on Join object on A(47698852085840) and B(47698852088016)(47698861282384) could not assemble any primary key columns for mapped table

0 个答案:

没有答案