在Django1.7中,对外键null的过滤不起作用

2024-05-14 13:15:03 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是一个模型设置和我正在尝试的查询的简短示例。这在django1.6中没有给我任何错误,但是在1.7中却给了我一个例外。“隐式”外键似乎在接口queryset上不可用。我尝试了select_-related('gwportprefix')和prefetch_-related('gwportprefix'),但没有成功。在

class Interface(models.Model):
    # Several fields here that are not related.
    pass

class GwPortPrefix(models.Model):
    interface = models.ForeignKey('Interface', db_column='interfaceid')

for gwport in Interface.objects.filter(gwportprefix__isnull=False):
    gwport_matches.add(gwport)

这将显示以下字段错误:

无法将关键字“gwportprefix”解析到字段中。选择是(一切都直接在接口上。无隐式外键)


Tags: 模型示例modelmodels错误selectinterface外键

热门问题