1

Would like to change a Column collation from utf8mb4_unicode_ci to utf8mb4_bin

Its updated SqlAlchemy model is

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

I have tried

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

but the upgrade keeps the MySQL collation of that column to the original utf8mb4_unicode_ci

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
ting12
  • 81
  • 10
  • I posted an answer but then I read it was alembic while I am working with `sqlalchemy-migrate` and I deleted it. Maybe you got a notification from Stackoverflow. Sorry, in that case – maggix Jun 22 '14 at 15:52
  • No I didn't. I changed the content above according to last improvements but the problem remains unsolved – ting12 Jun 23 '14 at 07:22
  • op.alter_column('table_name','col_name', type_=ty.VARCHAR(10, collation='utf8mb4_bin')) – ting12 Jul 01 '14 at 15:13

1 Answers1

1

Found out the right syntax, i.e.:

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'))
ting12
  • 81
  • 10
  • don't forget about `existing_type`, `existing_server_default`, and `existing_nullable` http://alembic.zzzcomputing.com/en/latest/ops.html#alembic.operations.Operations.alter_column – Carson Ip Nov 23 '17 at 07:20