Thanks for the swift reply, Mike! Unfortunately, I had some trouble running your code. I'm getting base = automap_base(MetaData()) File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/automap.py", line 848, in automap_base Base.__name__, AttributeError: 'MetaData' object has no attribute '__name__'
For some reason the class name doesn't seem to be parsing? Perhaps a related issue, I run into File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 73, in _escape_identifier value = value.replace(self.escape_quote, self.escape_to_quote) AttributeError: 'NoneType' object has no attribute 'replace' when I try base = automap_base() base.prepare(engine, reflect=True) however, base.prepare(engine, reflect=True, schema='report_rahuja') with the schema specified works just fine, which is what initially led me to believe that the base/engine require a schema. Any insight would be much appreciated. On Monday, September 19, 2016 at 8:09:29 PM UTC-7, Mike Bayer wrote: > > > > On 09/19/2016 08:43 PM, Rahul Ahuja wrote: > > Currently, I'm instantiating a new engine and declarative automap base > > for each MySQL database I'd like to include in my session and then > > individually > > mapping reflected tables to the relevant engines. Some sample code to > > clarify: > > > > | > > report_engine = create_engine(URL(drivername='mysql', > > host='prod-mysql-analytics-master.box', port='3306', > > query={'read_default_file':'/srv/db.cnf'}, database='report')) > > report_base = automap_base() > > report_base.prepare(report_engine, reflect=True) > > > > md_engine = create_engine(URL(drivername='mysql', > > host='prod-mysql-analytics-master.box', port='3306', > > query={'read_default_file':'/srv/db.cnf'}, database='md')) > > md_base = automap_base() > > md_base.prepare(md_engine, reflect=True) > > > you can connect to no specific database and schema qualify the tables > instead: > > > engine = create_engine("mysql://user:pass@host/") > base = automap_base(MetaData()) > > base.metadata.reflect(engine, schema="report") > base.metadata.reflect(engine, schema="md") > > my_base.prepare() > > > > > > This seems like a hack-ish approach so I'm wondering if there's a better > > way. Must a separate engine and base be created for each MySQL DB? > > nope > > Each > > DB resides on the same MySQL instance with the same host name. And must > > each table be explicitly bound in the session creation? > > definitely not. The SQLA docs hardly talk about "bound metadata" > anywhere and I don't know where people continue to get the impression > they need to do this. > > Still learning > > the ropes of SQLAlchemy so forgive me if these are obvious questions. > > Thanks for your time! > > > > -- > > 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 <javascript:> > > <mailto:sqlalchemy+unsubscr...@googlegroups.com <javascript:>>. > > To post to this group, send email to sqlal...@googlegroups.com > <javascript:> > > <mailto:sqlal...@googlegroups.com <javascript:>>. > > Visit this group at https://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. > -- 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+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.