Home Database Mysql Tutorial How Python operates MySQL to create time and update time

How Python operates MySQL to create time and update time

May 31, 2023 am 10:49 AM
mysql python

Creation time, update time

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

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;
Copy after login

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 of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the key information in the Debian logs that cannot be ignored What are the key information in the Debian logs that cannot be ignored Apr 02, 2025 am 08:12 AM

The log files of the Debian system are valuable resources for system administrators and developers to diagnose problems and monitor the operating status of the system. This article will focus on some key log information that cannot be ignored. Core system logs (usually located in /var/log/syslog or /var/log/messages) These logs record the core activities of the system, including: system startup and shutdown events: log kernel version, hardware detection results, etc., to help track startup failures or shutdown exceptions. Hardware failure alerts: such as disk errors, memory problems, etc., to promptly detect potential hardware problems. Service status changes: Record the service start, stop and restart events to facilitate monitoring of the service's health. User login/logout history:

What should I do if the '__builtin__' module is not found when loading the Pickle file in Python 3.6? What should I do if the '__builtin__' module is not found when loading the Pickle file in Python 3.6? Apr 02, 2025 am 07:12 AM

Error loading Pickle file in Python 3.6 environment: ModuleNotFoundError:Nomodulenamed...

How to apply Debian Strings in a website How to apply Debian Strings in a website Apr 02, 2025 am 08:21 AM

This article discusses how to optimize website performance on Debian systems. "DebianStrings" is not a standard term and may refer to tools or technologies used in Debian systems to improve website performance. The following are some practical tips: 1. It is recommended to use the Pagoda panel to simplify the installation and configuration process for web server and PHP environment configuration. It is recommended to install Nginx1.22.1 as the web server, PHP8.2 as the script interpreter, and MySQL10.7.3-MariaDB as the database system. Be sure to enable the necessary PHP extensions, such as fileinfo, opcache, memcached, red

Is Debian Strings compatible with multiple browsers Is Debian Strings compatible with multiple browsers Apr 02, 2025 am 08:30 AM

"DebianStrings" is not a standard term, and its specific meaning is still unclear. This article cannot directly comment on its browser compatibility. However, if "DebianStrings" refers to a web application running on a Debian system, its browser compatibility depends on the technical architecture of the application itself. Most modern web applications are committed to cross-browser compatibility. This relies on following web standards and using well-compatible front-end technologies (such as HTML, CSS, JavaScript) and back-end technologies (such as PHP, Python, Node.js, etc.). To ensure that the application is compatible with multiple browsers, developers often need to conduct cross-browser testing and use responsiveness

How to specify the database associated with the model in Beego ORM? How to specify the database associated with the model in Beego ORM? Apr 02, 2025 pm 03:54 PM

Under the BeegoORM framework, how to specify the database associated with the model? Many Beego projects require multiple databases to be operated simultaneously. When using Beego...

How to choose the solution for data consistency between MySQL and Redis: the difference between delayed double deletion and first modifying the database and then deleting the cache and applicable scenarios? How to choose the solution for data consistency between MySQL and Redis: the difference between delayed double deletion and first modifying the database and then deleting the cache and applicable scenarios? Apr 02, 2025 am 11:57 AM

Two solutions for data consistency between MySQL and Redis: delayed double deletion and first modifying the database and then deleting cache are used to handle data consistency problems in MySQL and Redis, ...

Does XML modification require programming? Does XML modification require programming? Apr 02, 2025 pm 06:51 PM

Modifying XML content requires programming, because it requires accurate finding of the target nodes to add, delete, modify and check. The programming language has corresponding libraries to process XML and provides APIs to perform safe, efficient and controllable operations like operating databases.

How to define an enum type in protobuf and associate string constants? How to define an enum type in protobuf and associate string constants? Apr 02, 2025 pm 03:36 PM

Issues of defining string constant enumeration in protobuf When using protobuf, you often encounter situations where you need to associate the enum type with string constants...

See all articles