On Thu, Jul 28, 2011 at 1:25 AM, Robert Forkel <[email protected]> wrote: > Hi all, > just encountered a problem with akhet's create_db script which had me > scratching my head for quite some time: I use the script to create the > tables and then populate the db. This worked fine with sqlite, but > when switching to postgresql, it always failed with > sqlalchemy.exc.InternalError: (InternalError) current transaction is > aborted, commands ignored until end of transaction block > > After some tial and error I found the following fix: Starting a new > transaction after the tables are created and before getting a session, > like so > > models.Base.metadata.create_all() > transaction.commit() > transaction.begin() > sess = models.Session() > > While this fixes my problem I have no clue whether this is the > recommended way or whether I'm doing something entirely wrong.
I'll test it with Postgresql and see. Some databases consider table-modifying commands to be outside of a transaction, and automatically commit beforehand. I think Postgres considers them inside the transaction. It shouldn't matter if you get the session before or afterward, although it may be necessary to commit or rollback both before and after modifying the tables. That's what I've done in utility scripts to avoid transaction errors. -- Mike Orr <[email protected]> -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
