创建时间、更新时间
default current_timestamp--表示当插入数据的时候,该字段默认值为当前时间 on update current_timestamp--表示每次更新这条数据的时候,该字段都会更新成当前时间
这两个操作是mysql数据库本身在维护,可以根据这个特性来生成【创建时间】和【更新时间】两个字段,且不需要代码来维护。
create table `test` ( `create_time` timestamp not null default current_timestamp comment '创建时间', `update_time` timestamp not null default current_timestamp on update current_timestamp comment '更新时间') engine=innodb default charset=utf8;
以上就是python操作mysql如何创建时间、更新时间的详细内容。