Thursday, 15 July 2010

postgresql - SQLAlchemy & postgres reflection: erroneously reflecting all schemas -



postgresql - SQLAlchemy & postgres reflection: erroneously reflecting all schemas -

i have reflection configured so:

meta = metadata() meta.reflect(bind=db.engine, schema='web') base of operations = automap_base(metadata=meta) base.prepare()

i thought schema keyword limit reflection specified schema, running app see reflects tables in schemas anyway, leads conflicts given have tables of same name in different schemas. base.classes contain wrong classes given uses wrong schema.

what options here?

you can limit tables reflected in metadata.reflect using only keyword.

meta.reflect(bind=db.engine, schema='web', only=tables)

if don't know tables in particular schema ahead of time, can utilize inspector object them.

insp = reflection.inspector.from_engine(db.engine) tables = insp.get_table_names(schema='web')

postgresql sqlalchemy

No comments:

Post a Comment