SQLAlchemy necessary table properties

create-table, mysql, reflection, sqlalchemy

Solution

The below should produce the same result semantically, although will not produce the same query:

class Entity(Base):
    __tablename__ = 'entities'
    __table_args__ = {'mysql_engine':'InnoDB'}
    id          = Column('id', Integer, primary_key=True)
    dn          = Column('dn', String(100, collation='utf8_unicode_ci'), unique=True)

I am only not sure how to specify collation for the whole table.

Problem

When writing SQLAlchemy models for a pre-existing database, how much information about a table do I have to give? Consider this table which is part of a MySQL database: ``` CREATE TABLE entities ( id INTEGER NOT NULL AUTO_INCREMENT, dn VARCHAR(100) NOT NULL UNIQUE, PRIMARY KEY (id) ) Engine=InnoDB, COLLATE utf8_unicode_ci; ``` Based on my testing, this would be sufficient to use it: ``` class Entity(Base): __tablename__ = 'entities' id = Column('id', Integer, primary_key=True) dn = Column('dn', String(100)) ``` But of course its missing the UNIQUE, AUTO_INCREMENT, Engine and COLLATE information. Does SQLAlchemy care about these? Of course I could use Reflection, but I would rather not due to consistency reasons.

Original source