> >> On Wed, 28 Jul 2010 15:17:09 +0530 (IST), Faheem Mitha 
> <fah...@email.unc.edu> wrote:
> >> >
> >> > Hi,
> >>
> >> > When calling create_all on a metadata instance after a 
> session has
> >> > alrady been opened causes the create_all to hang, I 
> assume because
> >> > the session is blocking the create_all. Is there some way to get
> >> > create_all to use the existing session, or any other graceful way
> >> > around this? Thanks.
> >>
> >> > I guess another option is to close and then reopen the 
> session after
> >> > the create_all has been called, but I'd prefer not to do that if
> >> > possible.
> >>
> >> Puting a session.close() before the create_all fixes the problem. I
> >> assume this means that create_all doesn't work in the middle of a
> >> transaction, or something like that?
> >

You can tell meta.create_all() to use the same underlying DB connection
as the session by using the session.connection() method with the 'bind'
parameter to create_all().

Ie.

  connection = session.connection()
  meta.create_all(bind=connection)

See the docs at
http://www.sqlalchemy.org/docs/session.html#using-sql-expressions-with-s
essions and
http://www.sqlalchemy.org/docs/reference/sqlalchemy/schema.html#sqlalche
my.schema.MetaData.create_all

Hope that helps,

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to