Suppose I have an engine
pointing at MySQL database:
engine = create_engine('mysql://arthurdent:answer42@localhost/dtdb', echo=True)
I can populate dtdb
with tables, FKs, etc by:
metadata.create_all(engine)
Is there an easy way to generate the SQL file that contains all the DDL statements instead of actually applying these DDL statements to dtdb
?
So far I have resorted to capturing SQLAlchemy log output produced by echo=True
, and editing it by hand. But that's just too painful.
It looks like SA has pretty elaborate schema management API, but I haven't seen examples of simply streaming the schema definitions as text.