MySQL DB migration: change of string length

点点圈 提交于 2020-04-07 05:08:34

问题


I'm using SQLAlchemy + alembic to manage my database. I had a string field which was 10 characters long and later on found out that it has to be 20. So I updated the model definition.

class Foo(db.Model):
    __tablename__ = 'foos'
    id = db.Column(db.Integer, primary_key=True)
    foo_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    name = db.Column(db.String(80))

When I run alembic revision --autogenerate, this was not detected. Now I did read the documentation and suspected that this might not be supported. How do I managed such changes in DB gracefully?


回答1:


You need to enable optional column type checking. See this for notes on what is checked by default

context.configure(
    # ...
    compare_type = True
)


来源:https://stackoverflow.com/questions/32536041/mysql-db-migration-change-of-string-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!