How to set the column which has default value to explicitly None

38 views
Skip to first unread message

Hong Minhee

unread,
Dec 13, 2012, 12:41:38 PM12/13/12
to sqlal...@googlegroups.com
Hi,

I have a model class which contains a nullable DateTime column, and its default value is now().  Its value is None immediately after it’s instantiated with Model(col=None), but it becomes filled to the current time after the session gets flushed.  (Note: I’m using sqlalchemy.ext.declarative with its default constructor.)  Does default value mean just alternative value to None?

I want to make the column to be set to the current time by default, but still possible to be explicitly set to None if needed.  Is there any way to achieve this?


Thanks,
Hong Minhee

Michael Bayer

unread,
Dec 13, 2012, 3:52:38 PM12/13/12
to sqlal...@googlegroups.com
tricky, perhaps try setting the column to the expression "sqlalchemy.sql.null()" for now.    A None does indicate "fire the default".

Hong Minhee

unread,
Dec 13, 2012, 9:39:23 PM12/13/12
to sqlal...@googlegroups.com
It works very well.  Thanks!
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/LO99H_UrY1wJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

Reply all
Reply to author
Forward
0 new messages