from datetime import datetime
from peewee import (AutoField, CharField, DateTimeField, FloatField,
IntegerField, Model, MySQLDatabase, TextField, SQL)
from config import DataBaseConfig
mysql_client = MySQLDatabase(
"your_database_name",
host=DataBaseConfig.host,
port=DataBaseConfig.port,
user=DataBaseConfig.user,
password=DataBaseConfig.password,
)
class CommonModel(Model):
id = AutoField(verbose_name="primary key")
create_time = DateTimeField(default=datetime.now, verbose_name="create time")
update_time = DateTimeField(default=datetime.now, verbose_name="update time", constraints=[SQL('ON UPDATE CURRENT_TIMESTAMP')])
class Meta:
database = mysql_client
You can refer to this document. Single-column indexes and constraints!