Hi Simon, Sorry, my bad.
I follow your tips to modify my program. It works. #!/usr/bin/env python # -*- coding:utf-8 -*- from sqlalchemy import create_engine from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, \ DateTime from sqlalchemy.dialects.oracle import NUMBER, VARCHAR2, DATE from sqlalchemy.orm import mapper from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class BandOrderOfLocalTesting(Base): __tablename__ = "band_order_of_local_testing" order_id = Column("order_id", NUMBER(18), primary_key=True) order_no = Column("order_no", VARCHAR2(255)) def __init__(self, order_id, order_no): self.order_id = order_id self.order_no = order_no def repr(self): return "BandOrderOfLocalTesting<'%s', '%s'>" % (self.order_id, self.order_no) engine = create_engine('oracle+cx_oracle://user:user@oracle_test', echo=True, convert_unicode=True, encoding='utf-8') Session = sessionmaker(bind=engine) session = Session() instance = session.query(BandOrderOfLocalTesting).first() print(instance) Thanks a lot. On 04/17/2013 06:00 PM, Simon King wrote: > On Wed, Apr 17, 2013 at 2:38 AM, Evan Jon <evanjon....@gmail.com> wrote: >> Hello all, >> >> I want to map a table whose name is BAND_ORDER_OF_LOCAL_TESTING. >> >> class BandOrderOfLocalTesting(Base): >> __TABLENAME__ = 'BAND_ORDER_OF_LOCAL_TESTING' >> order_id = Column("order_id", Number(18), primary_key=True) >> ... > > I assume the above is a typo - you need to be setting __tablename__, > not __TABLENAME__. > > >> Each time I got the following message: >> 013-04-17 09:26:55,857 INFO sqlalchemy.engine.base.Engine {'ROWNUM_1': 1} >> Traceback (most recent call last): >> File "tables.py", line 108, in <module> >> instance = session.query(BandOrderOfMonth).first() >> File >> "/usr/lib/python2.7/site-packages/SQLAlchemy-0.8.1dev-py2.7.egg/sqlalchemy/orm/query.py", >> line 2181, in first >> ret = list(self[0:1]) >> File >> "/usr/lib/python2.7/site-packages/SQLAlchemy-0.8.1dev-py2.7.egg/sqlalchemy/orm/query.py", >> line 2048, in __getitem__ >> return list(res) >> File >> "/usr/lib/python2.7/site-packages/SQLAlchemy-0.8.1dev-py2.7.egg/sqlalchemy/orm/loading.py", >> line 72, in instances >> rows = [process[0](row, None) for row in fetch] >> File >> "/usr/lib/python2.7/site-packages/SQLAlchemy-0.8.1dev-py2.7.egg/sqlalchemy/orm/loading.py", >> line 356, in _instance >> tuple([row[column] for column in pk_cols]) >> File >> "/usr/lib/python2.7/site-packages/SQLAlchemy-0.8.1dev-py2.7.egg/sqlalchemy/engine/result.py", >> line 71, in __getitem__ >> processor, obj, index = self._parent._key_fallback(key) >> File >> "/usr/lib/python2.7/site-packages/SQLAlchemy-0.8.1dev-py2.7.egg/sqlalchemy/engine/result.py", >> line 314, in _key_fallback >> expression._string_or_unprintable(key)) >> sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for column >> 'BAND_ORDER_OF_LOCAL_TESTING.order_id'" >> >> Is there a limit of table name in sqlalchemy? >> How to solve this problem? >> >> Best regards, >> Evan >> > The class that you are querying here (BandOrderOfMonth) doesn't match > the class that you mentioned above, so it's difficult to know what is > going on. A full running example would make it easier to understand. > > What database system are you working with? Different databases have > different rules about case sensitivity. From an SQL prompt, does > "SELECT * from band_order_of_local_testing" work, or give an error? > > In general, SQLAlchemy assumes that if you specify a table name with > any upper-case characters, then the table name is case-sensitive and > so it will be quoted in any queries. If you specify the table name in > all lower-case, it is assumed to be case-insensitive: > > > http://docs.sqlalchemy.org/en/rel_0_8/core/schema.html#sqlalchemy.schema.Table > > I suggest you try specifying the table name in lower-case and see if it works. > > Hope that helps, > > Simon > -- Best Regards, Qiu Dong -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.