You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#重新配置需要先删除目录 migrations目录下的所有文件
|
|
|
|
|
|
|
|
|
|
# 1、执行aerich初始化:aerich init -t 指定配置
|
|
|
|
|
aerich init -t settings.TORTOISE_ORM
|
|
|
|
|
|
|
|
|
|
# 将会在目录下生成空的 migrations 文件夹和 aerich.ini 文件
|
|
|
|
|
|
|
|
|
|
# 2、将模型映射到数据库中:
|
|
|
|
|
|
|
|
|
|
aerich init-db
|
|
|
|
|
|
|
|
|
|
# 此时数据库中就会生成对应的表
|
|
|
|
|
|
|
|
|
|
# migrations 下将会生成SQL语句
|
|
|
|
|
|
|
|
|
|
# aerich表下会存每个模型的内容
|
|
|
|
|
|
|
|
|
|
# 3、重新生成SQL语句:
|
|
|
|
|
aerich migrate
|
|
|
|
|
|
|
|
|
|
# 4、把新生成的SQL推送到数据库:
|
|
|
|
|
aerich upgrade
|
|
|
|
|
|
|
|
|
|
# 表信息
|
|
|
|
|
|
|
|
|
|
# 5、如果要回到上一个版本:
|
|
|
|
|
aerich downgrade
|
|
|
|
|
|
|
|
|
|
# 6、查看历史迁移记录:
|
|
|
|
|
aerich history
|
|
|
|
|
|
|
|
|
|
# 7、查看形成当前版本的迁移记录文件:
|
|
|
|
|
aerich heads
|
|
|
|
|
|
|
|
|
|
# 8、aerich 除了提供命令行之外,还提供了代码内执行的办法,从aerich引入 Command类即可,提供的方法与命令行一样
|
|
|
|
|
|
|
|
|
|
# 注:根据实测,在MySQL5.7上使用会报错:
|
|
|
|
|
# 换成MySQL8以后使用正常
|
|
|
|
|
|