Flask框架+mySQL数据库:误删migrations文件夹后再次创建时遭遇错误(Can't locate revision identified by ‘xxx’)
来源:互联网 发布:阿里巴巴阿里云事业部 编辑:程序博客网 时间:2024/06/05 16:27
先说一下如何把数据库与Flask框架下的Python后台(服务器)连接起来:
1、模型初始化环境:
命令:python manage.py db init
cmd的回应:
Creating directory F:\code\flask_project\migrations ... doneCreating directory F:\code\flask_project\migrations\versions ... doneGenerating F:\code\flask_project\migrations\alembic.ini ... doneGenerating F:\code\flask_project\migrations\env.py ... doneGenerating F:\code\flask_project\migrations\env.pyc ... doneGenerating F:\code\flask_project\migrations\README ... doneGenerating F:\code\flask_project\migrations\script.py.mako ... donePlease edit configuration/connection/logging settings in 'F:\\code\\flask_project\\migrations\\alembic.ini' before proceeding.
这时就可以在项目文件夹中看到子文件夹migrations
2、把表中模型映射到数据库中 先生成迁移文件
命令:python manage.py db migrate
cmd回应:
INFO [alembic.runtime.migration] Context impl MySQLImpl.INFO [alembic.runtime.migration] Will assume non-transactional DDL.INFO [alembic.autogenerate.compare] Detected added table 'answer'Generating F:\code\flask_project\migrations\versions\3007cf54a530_.py ... done
这时打开migration文件夹后再打开versions文件夹会看到形如3007cf54a530_.py文件和3007cf54a530_.cpy文件
3、再把迁移文件映射到数据库中
命令:python manage.py db upgrade
cmd回应:
INFO [alembic.runtime.migration] Context impl MySQLImpl.INFO [alembic.runtime.migration] Will assume non-transactional DDL.INFO [alembic.runtime.migration] Running upgrade -> 3007cf54a530, empty message
以上是正常的情况
今天我手残,项目做到一半把migrations文件误删了,而且这个文件删除后是无法找回的,回收站里是找不到的
于是我重新执行步骤一,成功
执行步骤二,报错:
alembic.util.exc.CommandError: Can't locate revision identified by '68c8e45e399c'
于是就懵逼了,后来终于找到一篇相关文章
把问题解决了
我的理解是:
当把后台与数据库建立关系后,双方会分别产生一个“接口”,后台的“接口”是migrations文件夹中的versions文件夹中的文件;数据库的“接口”是这个表“alembic_version”(蒸馏器版本?什么鬼名字?)
我把migrations删除后,alembic_version没有改变。当我新建一个migrations后,两个“接口”对不上了,所以会报错:
alembic.util.exc.CommandError: Can't locate revision identified by '68c8e45e399c'
所以这种错误最简单的解决办法就是把数据库中的alembic_version表删掉,然后就可以继续后面的操作了
其他关于用alembic进行版本控制的东西我就不多说了,有兴趣的请自行百度
- Flask框架+mySQL数据库:误删migrations文件夹后再次创建时遭遇错误(Can't locate revision identified by ‘xxx’)
- Heroku Postgres, db migrate fail: alembic.util.exc.CommandError: Can't locate revision identified by
- alembic.util.exc.CommandError: Can't locate revision identified by '4a5a7be6c05a'
- ERROR:can't locate file for xxx
- mysql数据库创建外键时报MySQL ERROR:1005 Can't create table (erron:150)错误
- Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10061),错误代码2003
- php程序mysql Can't connect to MySQL server on 'XXX' (13)错误解决办法
- Mysql启动错误: Can’t create test file xxx lower-test
- MySQL下“Can’t create/write to file xxx (Errcode: 13)”错误的解决方法
- mysql ERROR 1017 :Can't find file: '/xxx.frm'...错误的解决方法
- MySQL下“Can’t create/write to file xxx (Errcode: 13)”错误的解决方法
- MySQL下“Can’t create/write to file xxx (Errcode: 13)”错误的解决方法
- failed: Can’t locate DBD/mysql.pm的解决办法
- failed: Can’t locate DBD/mysql.pm的解决办法
- 二、错误:KeyError: "Can't open attribute (can't locate attribute: 'layer_names')"
- ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (111)
- Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (3)
- Can't locate LibXML.pm
- BeanUtils进行日期格式的拷贝转换
- 51 nod 1624 取余最长路 思路:前缀和 + STL(set)二分查找
- 写一个java死锁的demo
- 51 nod 1495 中国好区间 奇葩卡时间题 700ms 卡O(n*log(n)), 思路:O(n)尺取法
- Hybrid APP 混合开发模式的选择之路(六:JSBridge---Native代码与JS代码的通信桥梁)
- Flask框架+mySQL数据库:误删migrations文件夹后再次创建时遭遇错误(Can't locate revision identified by ‘xxx’)
- 文件操作Excel解析(2)读取和写入Excel文件_根据积分获取奖品
- 关于JetBrains CLion 激活 (CLion License Activation)的解决办法,带hosts详细修改
- springmvc传参问题
- 《你只是看起来很努力》——阅读笔记
- 51nod 1451 合法三角形 判斜率去重,时间复杂度O(n^2)
- (转)获取 request 中用POST方式"Content-type"是"application/x-www-form-urlencoded;charset=utf-8"发送的 json 数据
- 51nod 1126 求递推序列的第N项 思路:递推模拟,求循环节。详细注释
- (转)java代码发送JSON格式的httpPOST请求