Alembic:包括拒绝带有字符的字符串的约束

hli*_*117 2 python sqlalchemy alembic sql-like

我有一张看起来像这样的桌子

> select * from mytable
  id        value
0  1  hello world
1  2  hello_world
2  3  hello+world
Run Code Online (Sandbox Code Playgroud)

我试图强加一个 alembic 检查约束,其中值value不能有:字符。我将如何使用alembic.op对象来做到这一点?什么是upgrade()downgrade()功能?

编辑:我使用的数据库是 Mysql。

hli*_*117 5

在这种情况下,检查约束有效

def upgrade():
    op.create_check_constraint("constraint_name_here", "mytable", "value not like '%:%'")

def downgrade():
    op.drop_constraint("constraint_name_here", "mytable", type_="check")
Run Code Online (Sandbox Code Playgroud)

但是 mysql 不支持检查约束。¯_(?)_/¯