mirror of
https://github.com/jeffknupp/sandman2.git
synced 2026-04-25 00:25:49 +03:00
[GH-ISSUE #84] Not able to insert DateTime into sqlite #52
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
pull-request
question
refactoring
research
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/sandman2-jeffknupp#52
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @LorenzHenk on GitHub (Feb 18, 2019).
Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/84
I run
sandman2ctl sqlite+pysqlite:///storage.dbwith an sqlite database.The following error occurs if I try to insert
'2019-02-17T21:48:07.539Z'into a column with the typedatetime:@LorenzHenk commented on GitHub (Mar 14, 2019):
If anyone else has this problem as well, I've found the solution:
You need to create a custom type and cast the string to a datetime object yourself.
@Ujapy commented on GitHub (May 2, 2019):
Thanks for the reply, but where do I put the "custom type"?
@LorenzHenk commented on GitHub (May 2, 2019):
Here is a usage example:
@Ujapy commented on GitHub (May 2, 2019):
Thanks, I'll try it out and give you my feedback
On Thursday, May 2, 2019, Lorenz Henk notifications@github.com wrote:
@AllanSchergerGitHub commented on GitHub (Jun 25, 2020):
with python 3.6.9 I had to make a couple updates.
def datetime_sqlalchemy(value):
return datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S.%f')
and
datetime_created=datetime_sqlalchemy(str(datetime.datetime.now()))
and sqlalchemy is set up this way:
class Article(Base):
tablename = 'article'
datetime_created = Column(DateTime)
datetime_end = Column(DateTime)
Let me know if I'm doing this incorrectly ;but thought I'd leave an update on what worked for me.