Method one, the code is automatically inserted into the database after the time is generated
class Task(BaseModel):
__tablename__ = 'task_spiders'
task_num = db.Column(db.Integer, autoincrement=True, primary_key=True, nullable=False, comment='任务ID/序号 自增 任务唯一标识')
task_name = db.Column(db.String(255), nullable=False, comment='任务名称')
create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='任务的创建时间')
Method 2: When the database inserts a field, the database adds time
from sqlalchemy import func
class Task(BaseModel):
__tablename__ = 'task_spiders'
task_num = db.Column(db.Integer, autoincrement=True, primary_key=True, nullable=False, comment='任务ID/序号 自增 任务唯一标识')
task_name = db.Column(db.String(255), nullable=False, comment='任务名称')
create_time = db.Column(db.DateTime, server_default=func.now(), comment='任务的创建时间')