On Tue, Sep 08, 2009 at 17:35 -0400, Michael Bayer wrote:
> 
> Wolodja Wentland wrote:
> > I can't drop these constraints as well. Even if i accept that my tables
> > are created with primary key definitions the recipe you showed me does
> > not work. It fails with:
> >
> > --- snip ---
> > ...
> > /sqlalchemy/sql/compiler.pyc in _requires_quotes(self, value)
> >    1306     def _requires_quotes(self, value):
> >    1307         """Return True if the given identifier requires
> > quoting."""
> > -> 1308         lc_value = value.lower()
> >    1309         return (lc_value in self.reserved_words
> >    1310                 or self.illegal_initial_characters.match(value[0])
> >
> > AttributeError: 'NoneType' object has no attribute 'lower'
> 
> that's not a full stack trace but I would gather its looking for the name
> of the constraint.  so if you can provide names for your constraints
> that would allow the DropConstraint to work.

Yes you are right. That is not the full stack trace and the name of the
pkey constraint was missing. This, however, seems to be a bug within the
database reflection framework as these constraints have names within the
database and i am working on reflected tables here. It does not matter
whether i define names while creating the constraints as they are lost
as soon as i reflect the tables.

Any tips on how to dynamically create *Constraints? The inline_ddl idea
does not work and doing something like:

--- snip ---
tbl = metadata.tables[table_name]
...
new_pkc = PrimaryKeyConstraint(
    *pkey_columns_for_table(table_name),
    **{'name' : '%s_pkey'%(table)})
new_pkc._set_parent(tbl)
engine.execute(AddConstraint(new_pkc)
--- snip ---

... seems a bit hackish. It works however, but i am unsure if calling
_set_parent(tbl) really is safe and the correct way.

I am doing this because i have to create the same DB structure in a
bunch of databases and like to keep the table definition in one place.
The pkey_columns_for_table(..) function retrieves something like:
['foo_column', 'bar_column', ... ]

thanks

    Wolodja Wentland

Attachment: signature.asc
Description: Digital signature

Reply via email to