Thank you Michael, the argument "autoload_with=op.get_bind()" was what I missed.

I apologize for asking about something that was in the docs,

Stefan

> On 02 Oct 2014, at 18:15, Michael Bayer <mike...@zzzcomputing.com> wrote:
> 
> 
> On Oct 2, 2014, at 11:41 AM, Stefan Urbanek <stefan.urba...@gmail.com> wrote:
> 
>> Thanks, but that is for SQLAlchemy and we are already using constructions 
>> like that. That is not a problem at all. Problem is in Alembic migration - 
>> how to correctly get a reflected Table object from the database just being 
>> migrated? Something like:
>> 
>> table = Table("some_table", md)
>> 
>> where md is the actual reflected metadata of the existing schema in the 
>> database that the migration will be also upgrading.
> 
> OK, I'm pretty sure you know this already, so forgive me if I'm stating 
> things you already know and the question is still something I'm not getting.  
>   Table reflection with a Table is via the "autoload=True" argument, where 
> "autoload_with=<some bind>" allows you to send along the engine or connection 
> you want to reflect with 
> (http://docs.sqlalchemy.org/en/rel_0_9/core/reflection.html, which I'm sure 
> you've seen).   In an Alembic migration, the connection is available via 
> "get_bind()": 
> http://alembic.readthedocs.org/en/latest/ops.html#alembic.operations.Operations.get_bind.
>    So put those together and you get:
> 
> def upgrade():
>    meta = MetaData()
>    table = Table("some_table", meta, autoload=True, 
> autoload_with=op.get_bind())
> 
> the above, since it emits SELECT statements isn't compatible with "offline" 
> mode.
> 
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "sqlalchemy-alembic" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/sqlalchemy-alembic/eKqQWPAdunM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> sqlalchemy-alembic+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy-alembic" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy-alembic+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to