> -----Original Message-----
> From: sqlalchemy@googlegroups.com 
> [mailto:sqlalch...@googlegroups.com] On Behalf Of Laurent Rahuel
> Sent: 24 August 2009 12:16
> To: sqlalchemy
> Subject: [sqlalchemy] ForeignKey on a ForeignKey
> 
> 
> Hi all,
> 
> I'm stucked with a problem I'm not able to solve (SA 0.5.2). 
> I hope on 
> of you would be smarter than me.
> 
> Here is the problem:
> 
> """""""""""""""""""""""""""""""""""""""
> import sqlalchemy as sa
> 
> __metadata__ = sa.MetaData()
> 
> OBJECTS = sa.Table('objects', __metadata__,
>      sa.Column('id', sa.Integer, primary_key=True),
>      sa.Column('parent_id', sa.ForeignKey('objects.id', 
> ondelete='CASCADE', onupdate='CASCADE')),
>      sa.Column('name', sa.Text, index=True, nullable=False, 
> default='Root'),
> )
> 
> OBJECTSTREE = sa.Table('objects_tree', __metadata__,
>      sa.Column('id', sa.Integer, primary_key=True),
>      sa.Column('child_id', sa.ForeignKey('objects.id', 
> ondelete='CASCADE', onupdate='CASCADE'), primary_key=True),
>      sa.Column('parent_id', sa.ForeignKey('objects.parent_id', 
> ondelete='CASCADE', onupdate='CASCADE'), primary_key=True),
>      sa.Column('depth', sa.Integer, nullable=False, 
> index=True, default=0),
> )
> 
> When I call the create_all() method from metadata, I always get this 
> error -> sqlalchemy/types.py", line 375, in get_col_spec raise 
> NotImplementedError()
> 

I think your Column definitions are wrong - the second parameter to
Column should be the column type (Integer, String etc.). For foreign
keys, you can pass None, in which case the type will be the same as the
column that the key is pointing at.

eg.

sa.Column('child_id', None, sa.ForeignKey'objects.id',
ondelete='CASCADE', onupdate='CASCADE'), primary_key=True)

Hope that helps,

Simon

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