我在sqlite数据库中添加了一个条目,其值来自查询的前端:
data[{"date_operation":"25/06/2019","code":"4","status":1,"type":3,"mesto_hraneniya_id":2,"contragent":"","sum_operation":"2","rezerv":"5","cnt_doc":"3","stellag":"23","id":"App.model.OperationModel-1","id_type":0}]
要创建一个条目,请在我的烧瓶应用程序的views.py
中执行以下操作:
...
if method == 'Create':
data = request.form.get("data")
objFormat = json.loads(data)
object = Operation()
for key in objFormat:
if 'date_operation' in key:
key['date_operation'] = datetime.datetime.strptime(key['date_operation'], '%d/%m/%Y').date()
dict_add = key
for key in dict_add.keys():
setattr(object, key, dict_add[key])
try:
db.session.add(object)
db.session.commit()
return (str(object.id))
except SQLAlchemyError as e:
error = {"data": e, "meta": {"success": "false"}}
return (str(error))
...
就我而言,插入记录IntegrityError('(sqlite3.IntegrityError) datatype mismatch
时出现错误db.session.add(object)
我的错误在哪里,以及如何添加记录?
谢谢