SQLite Date类型仅接受Python日期对象作为输入 [英] SQLite Date type only accepts Python date objects as input

查看:364
本文介绍了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日期对象作为输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆