当我提交到数据库时,我收到一个IntegrityError。我正在尝试在start_time
和end_time
字段中提交时间,例如:%H:%M:%S
,因为HTML表单提示。 start_time = db.Column(db.DateTime, nullable=True)
字段可能不正确吗?
跟踪
IntegrityError
sqlalchemy.exc.IntegrityError:(sqlite3.IntegrityError)非空 约束失败:drivers.start_time [SQL:INSERT INTO驱动程序(名称, start_time,end_time)VALUES(?,?,?)] [参数:('Bob',None, 无)]
Models.py
from .extensions import db
from datetime import datetime
class Drivers(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(500))
start_time = db.Column(db.DateTime, nullable=True)
end_time = db.Column(db.DateTime, nullable=True)
miles = db.Column(db.Integer, primary_key=True)
def __init__(self, **kwargs):
super().__init__(**kwargs)
def calc_driver(self):
FMT = '%H:%M:%S'
total_time = datetime.strftime(start_time, FMT) - datetime.strftime(end_time, FTM)
distance = total_time * miles
return distance