Flask-Migrate用法(Target database is not up to date原因、No changes in schema detected原因)
来源:互联网 发布:淘宝管理团队 编辑:程序博客网 时间:2024/06/05 06:53
跟随Flask Web开发一本书第五章做Flask-Migrate数据库迁移,遇到了Target database is not up to date报错、No changes in schema detected报错。网上搜了很多帖子,中文的、英文的,最终在评论中找到了原因,原因就是我没明白Flask-Migrate数据库迁移的应用场景。
Flask-Migrate数据库迁移应用场景(针对《Flask Web》第五章的讲解,原文要表达如下意思):
比如要对User表增加phone字段,记录每个人手机号,这时候会用到Flask-Migrate,实现对表结构的更改
比如要对User表增加phone字段,记录每个人手机号,这时候会用到Flask-Migrate,实现对表结构的更改
比如要对User表增加phone字段,记录每个人手机号,这时候会用到Flask-Migrate,实现对表结构的更改
(重要的事情说三遍)
步骤:
1. 用db.create_all()创建了User表,表中有id、username、role_id三个字段
2.考虑到后期会对表字段扩充,先用Flask-Migrate对表进行了初始化“python hello.py db init”,执行后生成了migrations文件夹
3.比如在xx场景中,要求记录用户手机号,这时需要对User表增加phone字段,过程:
(1)更改hello.py的User表模型,增加phone字段
class User(db.Model):
......
id = ......
username=......
role_id =......
# 这是新增的phone字段
phone = db.Column(db.String(64))
(2)创建迁移脚本
$ python hello.py db migrate -m "add column phone"
你可以进migrations/version/XXXXXXadd column phone.py这个文件,看到upgrade函数里有了增加字段的sql语句,说明迁移脚本创建成功了
(3) 更新数据库
$ python hello.py db upgrade
4.查下User表结构,字段被增加进去了,且对原数据没影响
-----------------------------------------------------------------------------------------------------------------------------------
更多请关注:FlyTester,关注技术的测试者
QQ群:456850134
web站:www.flytester.org
微信扫描二维码关注:
- Flask-Migrate用法(Target database is not up to date原因、No changes in schema detected原因)
- flask数据库迁移问题: INFO [alembic.env] No changes in schema detected.
- “make: `run' is up to date”原因及解决办法
- 解决Django migrate No changes detected 不能创建表
- CommandError: Target database is not up-如何解决
- No changes made to database
- 【Maven in action】解决办法:Project configuration is not up-to-date with pom.xml. Run project ...
- No new migrations found. Your system is up-to-date.
- Hive metastore database is not initialized. Please use schematool(...) to create the schema.
- Hive metastore database is not initialized. Please use schematool(...) to create the schema.
- nod32 总是提示 operating system is not up to date
- Project configuration is not up-to-date with pom.xm
- Project configuration is not up-to-date with pom.xml
- Project configuration is not up-to-date with pom.xml
- Project configuration is not up-to-date with pom.xml
- Project configuration is not up-to-date with pom.xml
- Project configuration is not up-to-date with pom.xml
- Project configuration is not up-to-date with pom.xml
- 质数因子
- shell下使用mailx发送邮件
- abstract类和abstract方法
- springmvc实现restful返回xml格式的字符串
- [kuangbin带你飞]专题十 匹配问题 L - Cat VS Dog (二分图最大独立集)
- Flask-Migrate用法(Target database is not up to date原因、No changes in schema detected原因)
- ios 圆环加载动画
- 线性收敛的随机优化算法之 SAG、SVRG(随机梯度下降)
- iOS开放小技巧
- Unity-GlobalStatic
- Requirejs高级应用(五):模块的唯一性鉴别
- LintCode80:中位数
- 检测android手机是否支持nfc和hce
- jsp页面展示flash