I'm trying to use schema_translate_map to change a schema:
Base = declarative_base()
class DataAccessLayer():
def __init__(self):
conn_string = "mysql+mysqlconnector://root:root@localhost/"
self.engine = create_engine(conn_string)
Session = sessionmaker()
Session.configure(bind=self.engine)
self.session = Session()
def change_schema(self):
self.session.connection(execution_options={"schema_translate_map": {"belgarath": "belgarath_test"}})
class Player(Base):
__tablename__ = "player"
__table_args__ = {'schema': "belgarath"}
id_ = Column(Integer, primary_key=True)
dal = DataAccessLayer()
dal.change_schema()
qry = dal.session.query(Player.id_)
print(qry)
However, the SQL comes out as:
SELECT belgarath.player.id_ AS belgarath_player_id_
FROM belgarath.player
Instead of:
SELECT belgarath_test.player.id_ AS belgarath_test_player_id_
FROM belgarath_test.player
Where am I going wrong?