I'm trying to use data from a sequence to add columns to a SQLAlchemy table 
created declaratively. Here's what I'm doing:

class Sizing(Base):
    __tablename__ = 'sizing'
    id = Column(Integer, primary_key=True)

    [...]


for name in ('column1', 'column2', 'column3', ...):
    x = Column(type_=Integer)
    x.name = name
    Sizing.__table__.append_column(x)

This works as far as creating the table in the database, i.e. viewing the 
database shows columns named column1, column2, column3, etc, but code like 
getattr(sizing, 'column1')  (sizing is an instance of Sizing) is failinging 
with a message "'Sizing' object has no attribute 'column1'"

While code like:

Sizing.colum1 = Column(Integer)

works, but

Sizing.__dict__['column1'] = Column(Integer)
or

Sizing.__setattr__(Sizing, 'column1', Column(Integer))

fails

The reason I'm trying to use the sequence to create the colums is that data 
from the sequence containing the column names is used in other parts of the 
application and I'd like to maintain that data in just one place. It's okay if 
I have to rebuild the database when the columns in the sequence change.

Thanks,
Mark

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@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