【问题标题】:Django MongoDB DatabaseError at /admin/admin 处的 Django MongoDB 数据库错误
【发布时间】:2014-04-12 04:40:22
【问题描述】:

我正在尝试切换到将 MongoDB 与 Django 结合使用,但遇到了问题。即,该站点的某些部分给出了“/admin/myApp/myModel 处的数据库错误:数据库不支持此查询。”正如here 发布的类似问题所述,此错误来自.../admin/templates/change_list.html,并且抛出它的行是第 85 行:

{% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}

我有几个模型,包含各种 CharFields、IntegerFields、BooleanFields、DateFields、URLFields 和 DecimalFields。还有一个ManyToManyField:

class Trail(models.Model):
    sections = models.ManyToManyField(TrailSection)

我没有遇到用户等问题,但是每当我尝试访问 Trail 模型时,都会收到上述错误。单击 /admin 页面的 TrailSection 部分时没有问题,但单击 Trail 时出现此错误。可以打电话

associatedTrails = Trail.objects.filter(sections=sect).order_by('-date').values('trail_id','name')

但是当我以后使用时出现错误

for t in associatedTrails:

StackOverflow 上的另一个问题将此错误记录为需要修复的错误,但我的问题是:为什么这种情况有时只会发生?为什么 TrailSections 或者其他 /admin 页面没有问题,但是这个却抛出了错误?有什么好办法解决吗?

【问题讨论】:

    标签: python django mongodb


    【解决方案1】:

    原来 django-norel 不支持 ManyToManyFields。在大多数情况下,它们可以被 ListFields 所取代,这在 norel 中受支持,但在关系数据库中不受支持。更多详情请见here

    除了不支持 ManyToManyFields 之外,admin.py 中的 list_filter 只能包含一项。也许其他人可以评论原因,但使用单个过滤器删除所有模型都会消除错误。

    【讨论】:

      猜你喜欢
      • 2020-07-03
      • 2021-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-10
      • 2014-11-16
      • 2010-10-13
      • 2021-12-05
      相关资源
      最近更新 更多