Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlalchemy ORM : how to give some low-level specification?

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)

like image 717
Determinant Avatar asked Sep 15 '26 04:09

Determinant


1 Answers

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

like image 71
Gryphius Avatar answered Sep 17 '26 20:09

Gryphius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!