MySQL DB迁移:更改字符串长度 [英] MySQL DB migration: change of string length
本文介绍了MySQL DB迁移:更改字符串长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用SQLAlchemy + Alembic来管理我的数据库.我有一个长度为10个字符的字符串字段,后来发现它必须为20个字符.因此,我更新了模型定义.
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))
当我运行alembic revision --autogenerate
时,未检测到此错误.现在,我确实阅读了文档,并怀疑这可能不受支持.如何在数据库中优雅地管理此类更改?
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?
推荐答案
您需要启用可选的列类型此以获取有关默认检查内容的注释
You need to enable optional column type checking. See this for notes on what is checked by default
context.configure(
# ...
compare_type = True
)
这篇关于MySQL DB迁移:更改字符串长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文