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 On Aug 21, 2:22 pm, rajasekhar911 <rajasekhar...@gmail.com> wrote: > hi thanks for the reply.. > but one doubt > how will i access the "MyClass" inside MyClass > > i tried > ndex('ix_name_type', > MyClass.__table__.c.name,MyClass.__table__.c.type, unique=True) > it is giving the error > NameError: name 'MyClass' is not defined > > thanks > > On Aug 21, 2:04 pm, "King Simon-NFHD78" <simon.k...@motorola.com> > wrote: > > > > -----Original Message----- > > > From: sqlalchemy@googlegroups.com > > > [mailto:sqlalch...@googlegroups.com] On Behalf Of rajasekhar911 > > > Sent: 21 August 2009 07:30 > > > To: sqlalchemy > > > Subject: [sqlalchemy] Re: index in SA > > > > i want to add a composite index to the class inherited from > > > declarative_base > > > > I tried this, > > > > 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) > > > ) > > > > gave me an error, > > > File "/m2svn/trunk/src/model/MyClass.py", line 32, in MyClass > > > __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 2145, in _to_schema_column > > > raise exc.ArgumentError("schema.Column object expected") > > > sqlalchemy.exc.ArgumentError: schema.Column object expected > > > I'm not sure if this is the root cause of your error, but __table_args__ > > must either be a dictionary or a tuple where the last element is a > > dictionary (according > > tohttp://www.sqlalchemy.org/docs/05/reference/ext/declarative.html#table-c > > onfiguration) > > > Also, I think Index may require actual column parameters rather than > > strings (according > > tohttp://www.sqlalchemy.org/docs/05/metadata.html#indexes). You may be > > able to use something like the following after your class definition: > > > Index('ix_name_type', MyClass.__table__.c.name, > > MyClass.__table__.c.type, unique=True) > > > or even > > > Index('ix_name_type', MyClass.name, MyClass.type, unique=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 -~----------~----~----~----~------~----~------~--~---