最近在学Flask,书籍是《Flask.Web.Development》,其中数据库迁移工具使用的是Flask-Migrate,书中提到创建迁移脚本后更新数据库使用python manage.py db upgrade就可以更新数据库,但是我在使用过程中模型修改后使用上述命令并不起作用,每次都需要删除所有表然后重建,不知道使用过程中在哪一步出错了?
可以参考这个文章,Flask Web Development —— 数据库(下)
就是翻译我提到的书籍;第一步和第二步都已经做了,按照书中所说,当模型更改的时候只要执行更新语句,数据库对表进行更新而不会删除表中的数据,但是现在不起作用,比如我模型增加了字段,执行语句后数据库表对应字段没有增加。
Database migration is generally divided into two steps
Before
upgrade
you needmigrate
After modifying
model
Need to
python manage.py db migrate
first Then
python manage.py db upgrade
The problem I encountered was after changing the existing field type migration. There are no changes in the migration script. Solve. . . .
The title’s question seems to have gone beyond the scope of the original book.
The first time you enter python hello.py db upgrade is equivalent to db.creat_all(), and the next time you enter python hello.py db upgrade is to update the database. The questioner has already taken the first step, and now his attempt to update fails.
So the problem should occur in the step of updating the database. Post how you subsequently modified the database to continue analyzing the problem.
I am also currently studying, so I don’t know if this understanding is correct.