我这里有一个很奇怪的问题。
我正在将SQLite
与python和Flask
+ Flask-Sqlalchemy
结合使用。
我正在开发具有CRUD功能的flask Web应用程序(尽管目前不需要D),我有一个models.py
,routes.py
,form.py
,{ {1}}
table.py
显示用户打算在执行更新之前(通过带有更新页面链接的烧瓶表)更新的数据。该链接在route.py文件中调用特定的更新路由。
我可以通过终端和烧瓶形式向/从我的SQLite表添加/读取数据,没有问题,分配后,我也可以使用dB.session.commit通过终端直接在SQLite表中更新数据。新值覆盖旧值。但是,当通过烧瓶表单尝试使用与终端使用的更新路径和表单值相同时,更新将失败。
form.py
table.py
models.py
class SearchResultForm(FlaskForm):
agreement_no = StringField('Agreement No')
product = StringField('Product')
manufacturer = StringField('Manufacturer')
model = StringField('Model')
vehicle_age = StringField('Vehicle Age')
centre = StringField('Centre')
company = StringField('Company')
title = StringField('Title')
first_name = StringField('First Name')
middle_name = StringField('Middle Name')
last_name = StringField('Last Name')
contact_no = StringField('Contact No')
email = StringField('Email Address ')
adviser = StringField('Adviser')
complaint_no = StringField('Complaint No')
complaint_status = SelectField('Complaint Status', validators=[DataRequired()]
, choices=complaint_status_choices, default=complaint_status_choices[0])
complaint_group = StringField('Complaint Group')
complaint_source = StringField('Complaint Source')
complaint_narrative = TextAreaField('Complaint Narrative')
severity = SelectField('Severity', validators=[DataRequired()], choices=severity_choices, default=severity_choices[0])
date_received = DateTimeField('Date Received')
reg_due_date = DateTimeField('Reg. Due Date')
date_modified = DateTimeField('Date Modified', validators=[DataRequired()], default=dt.utcnow)
date_acknowledged = DateTimeField('Date Acknowledged', format='%d/%m/%Y', default=dt.utcnow)
date_escalated = DateTimeField('Date Escalated', format='%d/%m/%Y', default=dt.utcnow)
company_outcome = SelectField('Company Outcome', choices=company_outcome_choices, default=company_outcome_choices[0])
regulatory_outcome = SelectField('Regulatory Outcome', choices=regulatory_outcome_choices,
default=regulatory_outcome_choices[0])
regulatory_reportable = SelectField('Regulatory Reportable'
, choices=yes_no_choices, default=yes_no_choices[0])
goodwill_offered = SelectField('Goodwill Offered', choices=yes_no_choices, default=yes_no_choices[0])
goodwill_reason = StringField('Goodwill Reason')
goodwill_method = StringField('Goodwill Method')
goodwill_narrative = TextAreaField('Goodwill Narrative')
goodwill_amount = IntegerField('Goodwill Amount', default=0.00)
submit = SubmitField('Update')
routes.py
class Complaint(db.Model):
id = db.Column(db.Integer, primary_key=True, default=complaint_id)
complaint_group = db.Column(db.String(100), nullable=False)
complaint_source = db.Column(db.String(60), nullable=False)
complaint_status = db.Column(db.String(30), nullable=False)
severity = db.Column(db.String(30), nullable=False)
complaint_narrative = db.Column(db.Text, nullable=False)
agreement_no = db.Column(db.String(60), nullable=True)
product = db.Column(db.String(60), nullable=True)
manufacturer = db.Column(db.String(60), nullable=True)
model = db.Column(db.String(30), nullable=True)
vehicle_age = db.Column(db.String(30), nullable=True)
centre = db.Column(db.String(150), nullable=True)
company = db.Column(db.String(150), nullable=True)
title = db.Column(db.String(20), nullable=True)
first_name = db.Column(db.String(100), nullable=True)
middle_name = db.Column(db.String(100), nullable=True)
last_name = db.Column(db.String(100), nullable=True)
email = db.Column(db.String(100), nullable=True)
contact_no = db.Column(db.String(60), nullable=True)
date_received = db.Column(db.DateTime, default=dt.utcnow, nullable=True)
reg_due_date = db.Column(db.DateTime, default=(dt.utcnow() + timedelta(days=56)), nullable=True)
date_modified = db.Column(db.DateTime, default=dt.utcnow, nullable=True)
date_escalated = db.Column(db.DateTime, default=dt.utcnow, nullable=True)
date_acknowledged = db.Column(db.DateTime, default=dt.utcnow, nullable=True)
company_outcome = db.Column(db.String(60), nullable=True)
regulatory_outcome = db.Column(db.String(60), nullable=True)
regulatory_reportable = db.Column(db.String(10), nullable=True)
goodwill_offered = db.Column(db.String(10), nullable=True)
goodwill_method = db.Column(db.String(60), nullable=True)
goodwill_reason = db.Column(db.String(60), nullable=True)
goodwill_narrative = db.Column(db.Text, nullable=True)
goodwill_amount = db.Column(db.Integer, nullable=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
def __repr__(self):
return f"Complaint('{self.id}', '{self.complaint_group}', '{self.complaint_source}'," \
f" '{self.complaint_status}', '{self.complaint_narrative}','{self.severity}' ,{self.date_received}," \
f" {self.date_modified}, {self.date_acknowledged},{self.date_escalated}, " \
f"{self.reg_due_date},'{self.manufacturer}', '{self.model}'," \
f"'{self.vehicle_age}','{self.product}', '{self.agreement_no}'," \
f"'{self.title}','{self.first_name}', '{self.middle_name}'," \
f"'{self.last_name}','{self.email}', '{self.contact_no}'," \
f"'{self.company}','{self.company_outcome}', '{self.regulatory_outcome}'," \
f"'{self.regulatory_reportable}','{self.goodwill_offered}', '{self.goodwill_reason}'," \
f"'{self.goodwill_method}','{self.goodwill_narrative}','{self.goodwill_amount}', '{self.user_id}')"
我遇到的错误如下:
sqlalchemy.exc.StatementError:(builtins.TypeError)SQLite DateTime类型仅接受Python datetime和date对象作为输入。 [我已经检查了对象的类型,它实际上是python datetime对象,我也曾尝试将其转换为自定义datetime对象,但没有成功]
sqlalchemy.exc.InterfaceError:(sqlite3.InterfaceError)错误绑定参数0-可能是不受支持的类型。 [我应该指出,我已经能够使用终端通过终端成功更新SQLite表表单收到的值相同]
我在这里想念什么?
环境:[Windows 10专业版+ Pycharm专业版2020.1]