我有一个看起来像这样的表
> select * from mytable
id value
0 1 hello world
1 2 hello_world
2 3 hello+world
我试图施加一个 alembic 检查约束,其中 value
中的值不能有 :
字符。我将如何使用 alembic.op
对象执行此操作? upgrade()
和 downgrade()
函数是什么?
编辑:我使用的数据库是 Mysql。
最佳答案
在这种情况下,检查约束起作用
def upgrade():
op.create_check_constraint("constraint_name_here", "mytable", "value not like '%:%'")
def downgrade():
op.drop_constraint("constraint_name_here", "mytable", type_="check")
但是mysql不支持检查约束。 ¯_(ツ)_/¯
关于python - Alembic:包括约束以拒绝带有字符的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40540222/