SQLite Date类型仅接受Python日期对象作为输入

编程入门 行业动态 更新时间:2024-10-28 10:33:09
本文介绍了SQLite Date类型仅接受Python日期对象作为输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对SQLAlchemy有问题

I have a problem with SQLAlchemy

SQLite Date类型仅接受Python日期对象作为输入。[SQL:'UPDATE记录SET timestamp =?] [参数:[{'timestamp':(datetime.date(2017,6,15),)}]]]

SQLite Date type only accepts Python date objects as input.[SQL: 'UPDATE records SET timestamp=?][parameters: [{'timestamp': (datetime.date(2017, 6, 15),)}]]

这是我的Forms.py

This is my Forms.py

class DataForm(FlaskForm): timestamp = DateField("date", validators=[Required()]) class ModifyDataForm(FlaskForm): timestamp = DateField("date", validators=[Required()])

这是我的Models.py

This is my Models.py

class Record(db.Model): timestamp = db.Column(db.Date, default=date.today, index=True)

Views.py

def create(): form = DataForm() if form.validate_on_submit(): record = Record(timestamp=form.timestamp.data,) def modify(id): record = Record.query.get_or_404(id) form = ModifyDataForm(record) if form.validate_on_submit(): record.timestamp = form.timestamp.data, form.timestamp.data = record.timestamp

模板创建数据时,我使用引导程序的wtf.html

Template I use bootstrap's wtf.html

,输入 2017-06-18就可以了。但是当我更新数据时,sqlalchemy引发: >>> SQLite Date类型仅接受Python日期对象作为输入。[SQL:'UPDATE records SET timestamp =?] [参数:[{'timestamp':(datetime.date(2017,6,15),)}]]]

when I create a data, input '2017-06-18',that's ok.But when I update data,the sqlalchemy raise:>>>SQLite Date type only accepts Python date objects as input.[SQL: 'UPDATE records SET timestamp=?][parameters: [{'timestamp': (datetime.date(2017, 6, 15),)}]]

我在哪里错误? datetime.date不是Python日期对象吗?为什么第一次工作?我该如何解决。

Where am I wrong? Does datetime.date isn't a Python date object?Why the first time is worked? How can I fix it.

我的英语不好,如果有任何困惑,请再次询问我。

My English is poor, if any confused, ask me again.

谢谢!

推荐答案

在我的 views.py 中 函数修改。 我只是复制create中的代码。然后,在行尾加逗号。当我删除此逗号时,一切正常! 因此,如果您遇到相同的问题,请检查代码!

In my views.py function modify. I just copy the code from create.Then, it has a comma end the line. when I delete this comma, everything worked! So, if you have the same problem, check your code!

更多推荐

SQLite Date类型仅接受Python日期对象作为输入

本文发布于:2023-11-08 18:46:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570135.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   日期   类型   SQLite   Date

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!