- 安装
pip install aerich
- 创建models.py文件
from tortoise import Model, fields
class User(Model):
""" 用户基础信息 """
name = fields.CharField(max_length=24, description="姓名")
id_no = fields.CharField(max_length=24, description="身份证号")
- 创建配置db.py文件,配置TORTOISE_ORM
TORTOISE_ORM = {
"connections": {"default": "mysql://root:password@localhost/basename"},
"apps": {
"models": {
# models对应上面创建的models.py
"models": ["aerich.models", "models"],
"default_connection": "default",
},
},
}
- 生成初始化数据配置, db.TORTOISE_ORM是上面配置TORTOISE_ORM的路径
aerich init -t db.TORTOISE_ORM
- 初始化数据库
aerich init-db
- 修改数据模型后生成迁移文件
aerich migrate
- 执行迁移
aerich upgrade
- 回退到上一个版本
aerich downgrade
参考链接https://www.cnblogs.com/xiao-xue-di/p/15853578.html
浏览量:
64