使用Alembic upgrade()脚本更改MySQL列排序规则

时间:2014-06-19 14:06:08

标签: python alembic

想要将列整理从utf8mb4_unicode_ci更改为utf8mb4_bin

更新的SqlAlchemy模型是

col_name = Column(VARCHAR(10, collation='utf8mb4_bin'),  nullable=True)

我试过了

from alembic import op
import sqlalchemy as sa
import sqlalchemy.types as ty

def upgrade():

    op.alter_column('table_name',
        sa.Column('col_name', ty.VARCHAR(10, collation='utf8mb4_bin') )
    )

但是升级会将该列的MySQL排序规则保留为原始的utf8mb4_unicode_ci

1 个答案:

答案 0 :(得分:1)

找到正确的语法,即:

from alembic import op
import sqlalchemy.types as ty

def upgrade():

    op.alter_column('table_name','col_name', type_=ty.VARCHAR(10, collation='utf8mb4_bin'))