I'd like to create a mixin to specify naming conventions.

I tried both: 

class Base:
    metadata = MetaData(naming_convention={
        "ix": "ix_%(column_0_label)s",
        "uq": "uq_%(table_name)s_%(column_0_name)s",
        "ck": "ck_%(table_name)s_%(constraint_name)s",
        "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
        "pk": "pk_%(table_name)",
    })


and 

class Base:
    @declared_attr
    def metadata(cls):
        return MetaData(naming_convention={
            "ix": "ix_%(column_0_label)s",
            "uq": "uq_%(table_name)s_%(column_0_name)s",
            "ck": "ck_%(table_name)s_%(constraint_name)s",
            "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
            "pk": "pk_%(table_name)",
        })

But if I inspect a model created using this base I always got: 

>>> Test.metadata.naming_convention
immutabledict({'ix': 'ix_%(column_0_label)s'})

while I correctly have:

>>> Base.metadata.naming_convention
{'ix': 'ix_%(column_0_label)s',
 'uq': 'uq_%(table_name)s_%(column_0_name)s',
 'ck': 'ck_%(table_name)s_%(constraint_name)s',
 'fk': 'fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s',
 'pk': 'pk_%(table_name)'}

What is the correct way to do it? what am i doing wrong? Should I do this 
in my migration tool (alembic) ?
Also would it works for unique constraint on multiple column or do we have 
to name them explicitly.

Thanks a lot!

-- 
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