Home  >  Article  >  Database  >  How Python operates MySQL to create time and update time

How Python operates MySQL to create time and update time

WBOY
WBOYforward
2023-05-31 10:49:311240browse

Creation time, update time

DEFAULT CURRENT_TIMESTAMP
--表示当插入数据的时候,该字段默认值为当前时间
 
ON UPDATE CURRENT_TIMESTAMP
--表示每次更新这条数据的时候,该字段都会更新成当前时间

These two operations are maintained by the mysql database itself. You can generate two fields [creation time] and [update time] based on this feature. , and does not require code to maintain.

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;

The above is the detailed content of How Python operates MySQL to create time and update time. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete