Hello,
I'm following the documentation for reflecting database tables using `automap`: http://docs.sqlalchemy.org/en/latest/orm/extensions/automap.html#generating-mappings-from-an-existing-metadata.
When I don't specific a schema, and Postgres uses the default `public` schema, this works as expected, and I find the names of my tables:
>>> m = MetaData()>>> b = automap_base(bind=engine, metadata=m)>>> b.prepare(engine, reflect=True)>>> b.classes.keys()['ads', 'spatial_ref_sys', 'income']
But when I specific an explicit schema, I don't have access to the tables in `Base.classes` anymore.
>>> m = MetaData(schema='geography')>>> b = automap_base(bind=engine, metadata=m)>>> b.prepare(engine, reflect=True)>>> b.classes.keys()[]
The MetaData reflected correctly though:
>>> b.metadata.tablesimmutabledict({geography.usa_cbsa_centroids': Table('usa_cbsa_centroids', MetaData(bind=Engine(postgresql://asteroids:***@localhost:5432/asteroids)), Column('GEOID', VARCHAR(length=5), table=<usa_cbsa_centroids>, nullable=False), ...})
Note that the tables and columns are only known at runtime.
Any thoughts?
This is duplicated from http://stackoverflow.com/questions/29905160/automap-reflect-tables-within-a-postgres-schema-with-sqlalchemy, feel free to answer there as well.
Thanks,Sam
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
Thanks Michael! it was the lack of a primary key. I see references to it now that I know what to look for- a very interesting explanation: http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#how-do-i-map-a-table-that-has-no-primary-key
It looks like there's no mention of this requirement in the automap documentation page though: http://docs.sqlalchemy.org/en/latest/orm/extensions/automap.html. I'd be happy to add a brief note about it and submit a pull request if you'd like.
Just hit the issue tracker with this, and the two snags I encountered so far doing this. Hopefully it's not because I missed some glaring instructions about how to build the documentation?