> -----Original Message-----
> From: sqlalchemy@googlegroups.com 
> [mailto:sqlalch...@googlegroups.com] On Behalf Of rajasekhar911
> Sent: 21 August 2009 10:25
> To: sqlalchemy
> Subject: [sqlalchemy] Re: index in SA
> 
> 
> i tried
> 
> class MyClass:
>    __tablename__ = 'my_table'
> 
>     id = Column(Integer, primary_key=True)
>     name = Column(String, nullable=False)
>     type = Column(String, nullable=False)
>     __table_args__ = (
>             Index('ix_name_type', name , type ,unique=True)
>             )
> 
> it errors out
> 
> __table_args__ = (
>   File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5-py2.4.egg/
> sqlalchemy/schema.py", line 1461, in __init__
>     self._init_items(*columns)
>   File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5-py2.4.egg/
> sqlalchemy/schema.py", line 1465, in _init_items
>     self.append_column(_to_schema_column(column))
>   File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5-py2.4.egg/
> sqlalchemy/schema.py", line 1476, in append_column
>     self._set_parent(column.table)
>   File "/usr/lib/python2.4/site-packages/SQLAlchemy-0.5.5-py2.4.egg/
> sqlalchemy/schema.py", line 1469, in _set_parent
>     self.metadata = table.metadata
> AttributeError: 'NoneType' object has no attribute 'metadata'
> 
> thanks

The problem is that at the time you are calling "Index", the table
object doesn't exist. Apparently the Index object doesn't work with
declarative in this way.

However, if you just move your Index definition outside the class
definition completely, I think it should be fine.

ie.

class MyClass(Base):
   __tablename__ = 'my_table'

    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)
    type = Column(String, nullable=False)

Index('ix_name_type', MyClass.name, MyClass.type, unique=True)

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