Django查询异常__init __()得到了一个意外的关键字参数'hints'

时间:2015-01-28 22:49:39

标签: python django postgresql

我对Django / Python很新,并且在解决这个问题时遇到了一些麻烦。

Ubuntu 14.04 阿帕奇 Django 1.7.4 python 2.7 PostgreSQL的

__init__() got an unexpected keyword argument 'hints'
Request Method: GET
Request URL:    http://localhost/
Django Version: 1.7.4
Exception Type: TypeError

class Tier(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=100)

class Recipe(models.Model):
    id = models.UUIDField(auto_add=True, primary_key=True, default=uuid.uuid4)
    name = models.CharField(max_length=100)
    tier = models.ForeignKey(Tier)

以下是正在执行的代码,尝试检索层ID时出错。

firstRecipe = Recipe.objects.first()
tierId = firstRecipe.tier.id

我的数据库表是

web_recipe
    id
    name
    tier_id

web_tier
    id
    name

堆栈跟踪

    Traceback:
File "/home/user123/daoresources/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/user123/daoresources/web/views.py" in index
  7.    firstRecipe = Recipe.objects.first()
File "/home/user123/daoresources/env/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
  92.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/user123/daoresources/env/lib/python2.7/site-packages/django/db/models/query.py" in first
  508.         qs = self if self.ordered else self.order_by('pk')
File "/home/user123/daoresources/env/lib/python2.7/site-packages/django/db/models/query.py" in order_by
  812.         obj = self._clone()
File "/home/user123/daoresources/env/lib/python2.7/site-packages/django/db/models/query.py" in _clone
  955.         c = klass(model=self.model, query=query, using=self._db, hints=self._hints)

Exception Type: TypeError at /
Exception Value: __init__() got an unexpected keyword argument 'hints'

环境:

Django Version: 1.7.4
Python Version: 2.7.6
Installed Applications:
('web', 'django_pg')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')

编辑:我最后说了一下,把我的项目转换成了mysql,一切正常。如果有人提出了有效的答案,我将在新的项目上进行测试,并将其标记为正确。

1 个答案:

答案 0 :(得分:1)

从git安装最新版本的django-pgfields。它为我修好了。

如果从需求文件安装,则删除'django-pgfields'并添加

-e git://github.com/lukesneeringer/django-pgfields.git#egg=django-pgfields