简体   繁体   中英

Saving Time into Postgres database using SQLAlchemy

I have a Python application which utilizes SQLAlchemy to interface with a Postgres database. I am running into some issues saving a time object into the database.

I define two time columns where db is a SQLAlchemy object:

offHours                = db.Column(db.Time)
onHours                 = db.Column(db.Time)

Elsewhere in the code, I try to save a time value from a string:

offHours = "06:23"
onHours = "14:34"

Python then throws the following:

time data '06:23' does not match format '%HH:%MM'

I am confused by this error because the input is a valid 24 hour time. Additionally, the Python docs state that the correct formatter for a 24 hour timestamp is '%H:%M'. If this is the case, why is SQLAlchemy using '%HH:%MM' as it's time formatter?

In short, what am I doing wrong when saving these times? Is it my input or possibly some issue with my database configuration?

尝试保存datetime.time对象而不是字符串。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM