You can get to the column default value. class MyTable(Base): __tablename__ = 'table' id = Column(Integer, primary_key=True) name = Column(String, default='new name') def __init__(self, name=None): if name is not None: self.name = name else: self.name = getDefault(self, 'name') def getDefault(instance, colName): col = instance.__table__.c[colName] if col.default is not None: dflt = col.default.arg else: dflt = None return dflt
The column attribute you need to check for could also be server_default if that is what you specified in the metadata. Be careful, if the defaults are specified as server side defaults in an existing database where the DDL is not generated from SQLAlchemy, the SQLAlchemy metadata doesn't necessarily know about them unless you reflected the table or you coded the server side default in your code by hand. -- Mike Conley -- 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.