On 11/29/2016 12:43 PM, TomS. wrote:
Hi,

When I use __table_args__ like it is in the below example following
warning appears:

Column 'person_name' on table [...] being replaced by Column [...] which
has the same key.  Consider use_labels for select() statements.

I know that it can be solved by adding __table_args__ to inherited
models, but maybe there is more elegant way of doing it (and a way to
avoid pasting same line)?


why not use @declared_attr for __table_args__, so it gets created on the fly for each subclass?



class PPLTest(db.Model):

    __abstract__ = True

    person_pk_id = db.Column(db.Integer, primary_key=True)
    person_name = db.Column(db.String(1000))

    __table_args__ = (db.UniqueConstraint(u'person_name'),
{u'mysql_engine': u'InnoDB'})

class Level1(PPLTest):

    __tablename__ = u'ppl_level1'
    __bind_key__ = u'test'

class Level2(PPLTest):

    __tablename__ = u'ppl_level2'
    __bind_key__ = u'test'

Cheers and thank you!


--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to