On Feb 16, 2011, at 11:08 AM, Ivan wrote:

> 
> 
> I have table:
> 
> class Model(Base):
>    __tablename__ = 'model'
>    id =  Column(Integer,primary_key=True)
>    last_web_change_time = Column(DateTime, nullable=False, 
> default=time.asctime(time.localtime()))
>    name =  Column(String)
> 
> 
> When I update Model.name field, last_web_change_time didn't  fill 
> automatically ( is null ). Why ?

Three separate issues here, even though you're only asking about one.

1. you are passing a fixed time value to the "default".   Upon INSERT, the 
default value of this field will be the time that your program started running. 
  You'd want to ensure the value is a callable, such as a lambda:,  for this 
expression so that it is evaluated at execution time.

2. DateTime primarily accepts a Python datetime construct, so you'd be better 
off using "datetime.datetime.now()" for this field.

3. As for "update", you're looking for an "on update" default, which would look 
like "Column(DateTime, onupdate=datetime.datetime.now)".   Note "now" is not 
called - we pass the callable object itself.   If a lambda:, it would look like 
"Column(DateTime, onupdate=lambda: datetime.datetime.now())"

Documentation on this subject including examples of the above are at 
http://www.sqlalchemy.org/docs/core/schema.html#python-executed-functions .




> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to