如何在python 2.7中的ORM中映射具有外键属性的列的NULL值

时间:2015-05-26 21:40:37

标签: python sqlalchemy

我使用sqlalchemy作为ORM在Python 2.7中使用以下代码:

   if j.request.component:
        comp_prod = (j.request.component.name, j.request.component.product.name)
   else:
        comp_prod = ('None', 'None')

但崩溃时出现以下错误:

File "/remote/vtghome9/vgtools2/python2.5/lib/python2.5/site-packages/ChImE-1.1-py2.5.egg/kachori/extra/streams.py", line 4110
    comp_prod = (j.request.component.name, j.request.component.product.name)
AttributeError: 'NoneType' object has no attribute 'name'

我检查了"请求"表,以及此表中的一行 - "组件"一片空白。 我的问题是组件条目是否为NULL,这意味着" i.request.component"应该是没有权利?如果有条件的话,不应该转到其他部分吗?

0 个答案:

没有答案