How to use collate/charset key words in sqlalchemy?

1,907 views
Skip to first unread message

junepeach

unread,
Nov 19, 2012, 3:46:25 PM11/19/12
to sqlal...@googlegroups.com
If I should have a table 'mytable' defined like below in mysql database:

CREATE TABLE mytable (
id int(11) NOT NULL AUTO_INCREMENT,
fullname varchar(50) collate utf8_unicode_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

How can I add the 'collate' clause and CHARSET key word in alembic migration script?

op.create_table('mytable',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('fullname', sa.String(length=50)),
sa.PrimaryKeyConstraint('id')
)

Thank you very much!

Michael Bayer

unread,
Nov 19, 2012, 6:39:37 PM11/19/12
to sqlal...@googlegroups.com
the table modifiers here are accepted by Table as mysql_<name>=<value>, and alembic's create_table accepts these as well. Unfortunately they appear to be extremely under-documented in the SQLAlchemy documentation (see http://docs.sqlalchemy.org/en/rel_0_8/dialects/mysql.html#storage-engines for an example of charset):

create_table(..., mysql_DEFAULT_CHARSET='utf8', mysql_COLLATE='utf8_unicide_ci')
> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/YfV6pOwsg2QJ.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages