views:

177

answers:

3

Hi all

I am giving Pylons a try with SQLAlchemy, and I love it, there is just one thing, is it possible to print out the raw SQL CREATE TABLE data generated from Table().create() before it's executed?

A: 

SQLAlchemy is designed in such a way that doesn't allow echoing generated DDL statements without actually executing them. AFAIK, SQLAlchemy Migrate use mock engine to catch statements without executing when --preview_sql option is used, so using it is one way to solve your problem.

Denis Otkidach
SQLAlchemy Migrate was actually the thing I was looking for, though it need a bit of hacking in order for it to work, since I working on a project with dynamic tables and schemas, but then again, it would be boring if there was no challenge ;)
Mads Madsen
A: 
from sqlalchemy.schema import CreateTable

print CreateTable(table)

If you are using declarative syntax:

print CreateTable(Model.__table__)
Antoine Leclair