zPr*_*ima 5 python mysql sqlalchemy
我的引擎有一个属性dMeta,返回引擎元,然后我有一个类,有一个方法调用table,基本上这样做:
def table(meta):
return Table('table1',meta,autoload=True,schema=genShema())
Run Code Online (Sandbox Code Playgroud)
我正在自动加载表格:
t = SomeClass.table(engine.dMeta)
sql = select([t.c.ID, t.c.OPIS, t.c.IDG,
func.left(t.c.ID,2).label("Ident"),
(func.left(t.c.ID,2).label('Ident2')+' '+t.c.OPIS).label("show_as")])\
.where(t.c.ATRIBUT=="VPFA")
Run Code Online (Sandbox Code Playgroud)
SQLAlchemy给出了以下错误:
def __getattr__(self, key):
try:
return self._data[key]
except KeyError:
raise AttributeError(key)
Run Code Online (Sandbox Code Playgroud)
关键是ID,self._data contains'ID'= {Column}是一个table1.ID如果我把self._data[key]我得到正确的值,没有错误,那么这里有什么问题?
即使我重新运行代码几次,有时它会中断,有时它不会:/
看来您没有正确连接,并且引发了错误,请尝试此操作。
sql = select([t.c.ID, t.c.OPIS, t.c.IDG, func.left(t.c.ID,2).label("Ident"), func.concat(func.left(t.c.ID,2), literal(" "), t.c.OPIS)]).where(t.c.ATRIBUT=="VPFA")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1463 次 |
| 最近记录: |