python - Insert MySQL timestamp column value with SqlAlchemy -


i have sqlalchemy class mapping database table in mysql innodb. table has several columns , able populate them except timestamp column:

the mapping:

class harvestsources(base):     __table__ = table('harvested', metadata, autoload=true) 

the column on mysql timestamp has current_timestamp default value, when insert row it's being filled null.

if default not working need manually set timestamp, how either of them.

sqlalchemy code insert row table:

source = harvestsources() source.url = url source.raw_data = data source.date = ?  db.session.add(source) db.session.commit() 

datetime objects converted timestamps, can use:

from datetime import datetime ... source.date = datetime.now() 

or datetime.utcnow() if want save using utc. default (current_timestamp) uses local timezone, datetime.now() closer - should preferrable store time related data in utc, , timezone conversions when presenting data user.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -