Right, this is possible.

In my newbie status I did not know you can post-bind the metadata to a 
different engine.

A_metadata.bind = B_engine

And then:

A_metadata.create_all() does the magic.




On Friday, August 7, 2015 at 4:43:07 PM UTC-7, Luis Guzman wrote:
>
> Hi, 
>
> Is it possible to reflect from one engine and then use some of the tables 
> reflected as base to create tables in a second, different engine?
>
> A possible way:
>
> A_engine = create_engine("postgresql+psycopg2://...A...)
> B_engine = create_engine("postgresql+psycopg2://...B...)
>
> A_metadata = MetaData(schema='A', bind=A_engine)
> B_metadata = MetaData(schema='B', bind=B_engine)
>
> A_metadata.reflect(bind=A_engine)
> A_table = A_metadata.tables['A_table']
>
> A_table.metadata = B_metadata   
> A_table.schema = 'B'
>
> But now, I'm not sure how to tell A_metadata that it has a A_table to care 
> for.
>
> I've tried also with similar success using the 'autoload' and with the 
> 'automap_base',  instead of reflect.
>
> Any ideas? is this too hacky/crazy/stupid? If not, it is a better way I 
> haven't found? 
>
> The use case is that I'd like to reflect what are the tables from 
> production database, and use them as 'templates' to create a new database 
> for testing.
> That is, I want to be able to create in my test database with the actual 
> reflection of what it is in production, and use SQLAlchemy to control the 
> creation of fake data in it.
>
> Thanks in advance!
>
> Luis
>
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to