I'm using ORM in sqlalchemy. The actual situation is I'm also using MySQL database, and I want to set some table configuration that MySQL has to fit my project.(eg. mysql_engine='InnoDB', mysql_charset='utf8' and so on)
I know there's an approach using the SQL Expression provided by SA. But i prefer to use ORM interface instead. Any ideas?
P.S: How to make the same effect using 'class mytable' form (using ORM instead of SQL Expression maker)
you can pass mysql options in your Table definition in sqlalchemy.
http://www.sqlalchemy.org/docs/dialects/mysql.html#storage-engines
Table('mytable', metadata,
Column('data', String(32)),
mysql_engine='InnoDB',
mysql_charset='utf8'
)
edit://
if you use the declarative layer, you can use 'table_args' :
class Something(Base):
__tablename__ = 'something'
__table_args__ = {'mysql_charset': 'utf8', 'mysql_engine': 'InnoDB'}
http://www.sqlalchemy.org/docs/05/reference/ext/declarative.html#table-configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With