python - 使用 Alembic Upgrade() 脚本更改 MySQL 列排序规则

标签 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

最佳答案

找到正确的语法,即:

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'))

关于python - 使用 Alembic Upgrade() 脚本更改 MySQL 列排序规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24308610/

相关文章:

python-requests:限制遵循的重定向数量

postgresql - Alembic 无法自动转换为整数类型

python - 安装 ROS 时 Cmake 未检测到 boost-python

mysql - SQLAlchemy 更新时间在 Alembic 修订版中不起作用

python - Alembic SQLAlchemy 自动生成元数据错误

python - 如何在 SQLAlchemy 中表示自定义 PostgreSQL 域?

python - SQLAlchemy 数据库交互失败取决于我如何运行 python 脚本

python - 修补作为另一个类的属性的类实例属性

python - 在 Python 中自动比较 Winmerge

python - 具有最小分数的作业