what kind of constraint has that problem, keep in mind there’s primary key 
constraints, there’s a UNIQUE constraint if you say unique=True, etc.

need more info



dewey <de...@pathoz.com> wrote:

> I've added a naming convention to my metadata object (using declarative):
> customMetadata = MetaData(naming_convention=constraintNameConv)  # 
> schema='pay'
> Base = declarative_base(cls=DbBase, metadata=customMetadata, 
> constructor=record_constructor)
> 
> and now I'm getting this error when I try to generate the DB (new & empty):
> Naming convention including %(constraint_name)s token requires that 
> constraint is explicitly named
> 
> But all of my explicit constraints ARE NAMED as so:
> UniqueConstraint('sit_id', 'typ_id_ctr', 'typ_id_cont', 'version', 
> name='sit_ctr_con_vers_uc')
>  
> I'm assuming things like "unique", "index" in the declarative class (column 
> construct) use the db field name?
>  
> I'm wondering if this trick we used below:
> @event.listens_for(“before_parent_attach”, Column)
> Is related to the problem?
> 
> Similarly, when I run:
> alembic upgrade head
> 
> I'm getting errors like:
> Can't DROP 'cat_ctr_att_ibfk_4'; check that column/key exists
> 
> And wondering if there is any connection between the two problems.
> 
> Thanks for tips.
> D
> 
> 
>  
> Friday, December 12, 2014 8:18:00 PM UTC-6, dewey wrote:
> Ok, I figured it out......parent (param 2) is the table obj, not the 
> declarative class....which is fine
> 
> btw:   params for:
> @event.listens_for(“before_parent_attach”, Column)
> need to be reversed as so:
> @event.listens_for(Column, “before_parent_attach”)
> 
> Thanks again for your help!!  This tool rocks ;-)
> Dewey
> 
> On Friday, December 12, 2014 7:48:16 PM UTC-6, dewey wrote:
> Mike,
> Thanks so much for the answer....I've watched a bunch of your 
> video's....really good stuff.
> 
> My prefix is derived from an attribute on the model-class.  
> Is that what parent (2nd param to your event listener) will give me?
> Said a different way, how do I get a ref to the class in which the column is 
> being (has been) defined.
> 
> Thanks again.
> Dewey
> 
> On Friday, December 12, 2014 6:05:06 PM UTC-6, Michael Bayer wrote:
>> On Dec 12, 2014, at 4:12 PM, dewey <de...@pathoz.com <>> wrote:
>> 
>> after re-reading the docs, it seems I misunderstood the purpose of:
>> 
>> __mapper_args__ = {'column_prefix': 'ste_'}
>> 
>> that option is adding the prefix onto the Class att names, NOT onto the 
>> actual DB column names in the table....
>> 
>> I'm looking for a way to add a global prefix onto my DB column names.
>> 
>> All suggestions appreciated.
> 
> 
> assuming this is a fixed prefix that is just set up once you would either 
> make a function:
> 
> from sqlalchemy import Column as _Column
> 
> def Column(name, **kw):
>     newname = “myprefix_%s” % name
>     return _Column(newname, key=name, **kw)
> 
> or if that is too simple, use the before_parent_attach event, which you’d 
> have to stick on Column:
> 
> @event.listens_for(“before_parent_attach”, Column)
> def attach(target, parent):
>     target.name <http://target.name/> = “myprefix_%s” % target.name 
> <http://target.name/>
>     # target.key is OK here
> 
> -- 
> 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 http://groups.google.com/group/sqlalchemy 
> <http://groups.google.com/group/sqlalchemy>.
> For more options, visit https://groups.google.com/d/optout 
> <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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to