I had to use __tablename__ = 'some_name' __table_args__ = (PrimaryKeyConstraint('id'), ) in my declarative models to get the same result.
Thanks Mike, that clears it all up. On Mon, Jan 25, 2016 at 6:12 PM, Mike Bayer <mike...@zzzcomputing.com> wrote: > > > On 01/25/2016 02:51 PM, Gastón Avila wrote: > > Hi all, > > > > I have set up specific naming conventions in a Flask-Sqlalchemy app > > using the metadata argument and it all seems to work except for naming > > PRIMARY KEY constraints. Here is what I have > > > > | > > self.db.init_app(app) > > self.db.Model.metadata =MetaData( > > schema=self.app.config['SQLALCHEMY_DATABASE_SCHEMA'], > > naming_convention={ > > "columns":columns, > > "ix":'%(table_name)s_%(columns)s_idx', > > "uq":"%(table_name)s_%(columns)s_key", > > "fk":"%(table_name)s_%(columns)s_fkey", > > "pk":"%(table_name)s_%(columns)s_pkey" > > } > > ) > > | > > > > and the *columns* helper is defined by: > > | > > defcolumns(constraint,table): > > return"_".join([col.name forcol inconstraint.columns]) > > | > > > > It works for every single kind except for the *primary key* property of > > the naming convention obj. When printed out, the helper receives a > > constraint argument that when > > | > > printconstraint > > | > > is added, gives *PrimaryKeyConstraint()* so no columns can be gotten > > from it. > > Table makes its own PrimaryKeyConstraint up front and the naming > convention is not "deferred", that is the convention is called > immediately, so you'd need to specify a PrimaryKeyConstraint explicitly; > the good news is you can forego the "primary_key=True" flag within > columns when working this way: > > def columns(constraint, table): > return "_".join([col.name for col in constraint.columns]) > > from sqlalchemy import MetaData, Integer, Column, Table, create_engine, > PrimaryKeyConstraint > > m = MetaData( > naming_convention={ > "columns": columns, > "ix": '%(table_name)s_%(columns)s_idx', > "uq": "%(table_name)s_%(columns)s_key", > "fk": "%(table_name)s_%(columns)s_fkey", > "pk": "%(table_name)s_%(columns)s_pkey" > } > ) > > t = Table('t', m, Column('id', Integer), PrimaryKeyConstraint('id')) > > e = create_engine("sqlite://", echo=True) > m.create_all(e) > > > > > > > Does anyone know what could be causing this? I have a guess that it > > might be this flask-sqlalchemy pluging but cannot figure it out. > > > > Thanks a lot! > > > > > > -- > > 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 > > <mailto:sqlalchemy+unsubscr...@googlegroups.com>. > > To post to this group, send email to sqlalchemy@googlegroups.com > > <mailto:sqlalchemy@googlegroups.com>. > > Visit this group at https://groups.google.com/group/sqlalchemy. > > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to a topic in the > Google Groups "sqlalchemy" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/sqlalchemy/GjNmo882Di8/unsubscribe. > To unsubscribe from this group and all its topics, 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. > -- 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.