SQLite Date type only accepts Python date objects as input

此生再无相见时 提交于 2019-12-13 00:18:43

问题


I have a problem with SQLAlchemy

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

This is my Forms.py

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

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

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

Template I use bootstrap's wtf.html

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),)}]]

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.

Thanks!


回答1:


I'm so stupid.
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!



来源:https://stackoverflow.com/questions/44607244/sqlite-date-type-only-accepts-python-date-objects-as-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!