Sql Alchemy And Generating Alter Table Statements
I want to programatically generate ALTER TABLE statements in SQL Alchemy to add a new column to a table. The column to be added should take its definition from an existing mapped c
Solution 1:
After tracing engine.create_all() with a debugger I've discovered a possible answer:
>>>engine.dialect.ddl_compiler(... engine.dialect,... DBChain.__table__.c.rName ) \....get_column_specification(... DBChain.__table__.c.rName )
'"rName" VARCHAR(40)'
The index can be created with:
sColumnElement = DBChain.__table__.c.rName
if sColumnElement.index:
sIndex = sa.schema.Index(
"ix_%s_%s" % (rTableName, sColumnElement.name),
sColumnElement,
unique=sColumnElement.unique)
sIndex.create(engine)
Post a Comment for "Sql Alchemy And Generating Alter Table Statements"