SQLAlchemy: A table reflected from an existing table gets different table collation

I have been playing around with the SqlAlchemy example code examples.versioned_history.history_meta : https://docs.sqlalchemy.org/en/14/_modules/examples/versioned_history/history_meta.html.

When I use it to create history table from my existing tables, they are all created with incorrect table collation. The existing tables are all created in Declarative as follows:

from history_meta import Versioned

class Thingo(Base,Versioned):
  __tablename__ = 'thingos'
  __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}

Which leads to tables with a table collation property of utf_general_ci (good!). When I use the example history_meta code to generate a thingos_history instance, these tables are created with a table collation property of latin1_swedish_ci (bad!).

What is the best way to ensure that the dynamically generated thingos_history table gets the same table collation property as the source table?

(If this isn't easily achieved on a per-column/per-table basis, it is acceptable for all _history tables to be created with UTF8 encoding)

Read more here: https://stackoverflow.com/questions/67412976/sqlalchemy-a-table-reflected-from-an-existing-table-gets-different-table-collat

Content Attribution

This content was originally published by RadioRaheem at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: