简体   繁体   中英

Db2 with SQLAlchemy, how to specify default schema

I'm trying to map an existing DB2 database to new python ORM objects. I wrote a very simple mapper class:

class Storage(Base):

    __tablename__ = 'T_RES_STORAGE_SUBSYSTEM'        

    id = Column(Integer,primary_key=True,name='SUBSYSTEM_ID')
    name = Column(String(255),name='NAME')
    namealias = Column(String(256),name='NAME_ALIAS')

But when I try to map it, by executing a query it puts the DB2ADMIN .tablename in front of every query, which of course lead to errors. If I execute the query manually by prepending TPC .tablename to it, then everything works without issues.

How can I specify in a table definition which schema to use?

Ok so after the help of mustaccio, I found out that in the table_args you have to add schema :

class Storage(Base):

    __tablename__ = 'T_RES_STORAGE_SUBSYSTEM'
    __table_args__ = {'schema' : 'TPC'}

    id = Column(Integer,primary_key=True,name='SUBSYSTEM_ID')
    name = Column(String(255),name='NAME')
    namealias = Column(String(256),name='NAME_ALIAS')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM