limiting reflect and automap to single schema only

10 views
Skip to first unread message

mdob

unread,
May 12, 2022, 12:40:27 PM5/12/22
to sqlalchemy
Hi Everyone, 

SQLAlchemy nicely reflects tables and builds model using automap. When providing the parameter shema to reflect, tables from that schema are discovered. I've noticed that tables from other schemas will also be included if there is a foreign key to the other schema. 

It's all good but what should I do to reflect and automap only tables from the schema i.e. ignore tables and relationships to other schemas?

I've done it by removing unwanted:
  • foreign keys that refer to other schemas from table objects
  • foreign keys constraints that refer to other schemas from table objects
  • foreign keys that refer to other schemas from column objects
I've attached the script that does what I've explained above.

It seems to work and no errors when reflect, automap and making queries even with joins but is it OK to do it this way? 

Much appreciate any comments.

Cheers,
Michal

single_schema_reflect.py
Reply all
Reply to author
Forward
0 new messages