you should use lower case names for the columns if they are case  
insensitive names.  Check the API reference with regards to the  
Column() constructor for details on this.

Also ForeignKey() by default should reference the given "key" on the  
Column, not the "name".  I see you have used the "key" parameter below.


On Dec 26, 2008, at 9:59 AM, ibrahim.z.hi...@gmail.com wrote:

>
> hi
>
> i am using sqlalchemy with turbogears and postgresql,
>
> for some reasons in db at my tables i am using capital column names,
> so in my column definitions i am using key parameter. like,
>
> users_table = Table('TG_USER', metadata,
>    Column('USER_ID', Integer, primary_key=True, key='user_id'),
>    Column('USER_NAME', Unicode(16), unique=True, key='user_name'),
>    Column('EMAIL_ADDRESS', Unicode(255), unique=True,
> key='email_address'),
>    ..................
>
> groups_table = Table('TG_GROUP', metadata,
>    Column('GROUP_ID', Integer, primary_key=True, key='group_id'),
>    Column('GROUP_NAME', Unicode(16), unique=True, key='group_name'),
>    .................
>
> user_group_table = Table('USER_GROUP', metadata,
>    Column('USER_ID', Integer, ForeignKey
> ('BEYAZ_MASA.TG_USER.USER_ID',
>        onupdate='CASCADE', ondelete='CASCADE'), primary_key=True,
> key='user_id'),
>    Column('GROUP_ID', Integer, ForeignKey
> ('BEYAZ_MASA.TG_GROUP.GROUP_ID',
>        onupdate='CASCADE', ondelete='CASCADE'), primary_key=True,
> key='group_id'),
>    schema='BEYAZ_MASA'
> )
>
> everything seems fine, but when i run turbogears aplication i got
> error in schema.py file at ForeignKey class, column funtion at line
> 859,
>
> when i check whats going on i see that
> _column = table.c[colname] - table.c is a dictionary and keys are the
> keys which i use in my column definition but the line checking the
> keys via colname so i make some changes on function like,
>
> try:
>                if colname is None:
>                    # colname is None in the case that ForeignKey
> argument
>                    # was specified as table name only, in which case
> we
>                    # match the column name to the same column on the
>                    # parent.
>                    key = self.parent
>                    _column = table.c[self.parent.key]
>                else:
>                    if self.parent.key: #new line
>                        _column = table.c[self.parent.key] #new line
>                    else: #new line
>                        _column = table.c[colname] #new line
>            except KeyError, e:
>                raise exc.NoReferencedColumnError(
>                    "Could not create ForeignKey '%s' on table '%s': "
>                    "table '%s' has no column named '%s'" % (
>                    self._colspec, parenttable.name, table.name, str
> (e)))
>
> now everything working fine
>
> thanks..
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to