本地写了一个model的用户类,数据库连接信息正确,执行下面2条命令进行数据库迁移。
flask db migrate 生成迁移文件
flask db upgrade 执行迁移文件的升级
发现执行完后:提示没有检测到数据的更新
PS C:\Users\mu>flask db migrate
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.env]No changes in schema detected.
PS C:\Users\mu> flask db upgrade
INFO [alembic.runtime.migration] Context impl MySQLImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
项目目录结构:
MU
app/
models
auto_model.py
migrations/
很郁闷,为什么执行生成迁移文件后,提示没有数据更新。
最后找了很多的相关材料找到了解决方法,是因为Alembic没有获得模型的信息,导致无法比较差异。
解决方法
需要在migrations/env.py中导入相关的模型,让Alembic能够获取到模型的元数据。
比如我的项目目录结构是:
MU
app/
models
auto_model.py
migrations/
那么需要再migrations/env.py中添加导入模型命令
from app.models.auto_model import *
