比如有一个简单的模型
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(32), index=True)
一开始,username的长度限制在32,现在将其增大,比如说变为128,flask-migrate似乎不会检测到这个String变长的变化。
我使用了命令自动生成迁移脚本
python code.py db migrate -m "some comment"
python code.py db upgrade
之后,发现username的列的长度依旧被限制在32.
如何进行String长度的变化这种迁移?
alembic supports detecting field length changes, but it is not the default and needs to be configured.
Settings
compare_type
为True
可以检查出类型字段的改变比如字段长度,设置compare_server_default
You can check out the changes to the default values of the set fields.Detailed reference documentation
flask-migrate will not detect column modifications, but you can do this
First add a row under User, then migrate, then make modifications, delete the previously added rows, and then add a few more rows. Please note that It may not work under sqlite
python code.py db edit
Reference
http://alembic.readthedocs.io/en/latest/ops.html