张家港网站包年,深圳电力建设公司,wordpress 调用评论数,营销建设网站制作项目基于Vue3.0, FastAPI的模板管理系统#xff0c;从网上找了各种资源去实践#xff0c;现在将总结发出来#xff0c;分享给大家#xff0c;希望帮助大家少走些弯路。
准备工作 # tortoise-orm pip install tortoise-orm # MySQL pip install tortoise-orm[asyncmy] # 迁…
项目基于Vue3.0, FastAPI的模板管理系统从网上找了各种资源去实践现在将总结发出来分享给大家希望帮助大家少走些弯路。
准备工作 # tortoise-orm pip install tortoise-orm # MySQL pip install tortoise-orm[asyncmy] # 迁移工具 pip install aerich 1. 项目目录 2. 准备好数据库MySQL 3. 连接参数
#settings.pyTORTOISE_ORM {connections: {default: mysql://root:123456127.0.0.1:3306/printer},apps: {models: {models: [aerich.models, models],default_connection: default,},},
}# 须添加aerich.models 后者models是上述models.py文件的路径
# connections 相信大家都能看得懂
4. 简单定义一下User表
#models.pyfrom tortoise import fields
from tortoise.models import Modelclass User(Model):id fields.IntField(pkTrue)username fields.CharField(max_length50, uniqueTrue)password fields.CharField(max_length50, uniqueTrue)email fields.CharField(max_length100, uniqueTrue)def __str__(self):return self.username运行命令
1. 初始化 # 执行aerich初始化 aerich init -t settings.TORTOISE_ORM # 命令行返回 Success create migrate location ./migrations Success write config to pyproject.toml # 数据库初始化 aerich init-db # 命令行返回 Success create app migrate location migrations\models Success generate schema for app models 2. 表创建成功 表跟新
在开发过程中涉及到表的修改models.py代码修改后执行命令 # 修改model类重新生成迁移文件 aerich migrate # 执行修改 aerich upgrade Success migrate 1_20240116132755_update.py # 回退修改 aerich downgrade