Reputation: 1289
I recently updated a project that was working with Django rest framework 2.4.2 to the newly 3.1 version but now I'm getting a:
'module' object has no attribute 'HStoreField'
That happens to all the endpoints including the "/"
Any suggestions? my Django version is 1.8 and python 2.7.6
Traceback:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.8.dev20140910173004
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest',
'rest_framework',
'geoposition',
'rest_framework_swagger',
'PIL',
'rest_framework.authtoken',
'corsheaders')
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')
Traceback:
File "/Users/marcus/PycharmProjects/django-framework/django-trunk/django/core/handlers/base.py" in get_response
112. resolver_match = resolver.resolve(request.path_info)
File "/Users/marcus/PycharmProjects/django-framework/django-trunk/django/core/urlresolvers.py" in resolve
362. for pattern in self.url_patterns:
File "/Users/marcus/PycharmProjects/django-framework/django-trunk/django/core/urlresolvers.py" in url_patterns
398. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/marcus/PycharmProjects/django-framework/django-trunk/django/core/urlresolvers.py" in urlconf_module
392. self._urlconf_module = import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/Users/marcus/Google Drive/Spring2015/AppContest/MyApplication/Backend/Backend/urls.py" in <module>
3. from rest_framework import routers
File "/Library/Python/2.7/site-packages/rest_framework/routers.py" in <module>
23. from rest_framework import views
File "/Library/Python/2.7/site-packages/rest_framework/views.py" in <module>
91. class APIView(View):
File "/Library/Python/2.7/site-packages/rest_framework/views.py" in APIView
94. renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES
File "/Library/Python/2.7/site-packages/rest_framework/settings.py" in __getattr__
206. val = perform_import(val, attr)
File "/Library/Python/2.7/site-packages/rest_framework/settings.py" in perform_import
158. return [import_from_string(item, setting_name) for item in val]
File "/Library/Python/2.7/site-packages/rest_framework/settings.py" in import_from_string
170. module = importlib.import_module(module_path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/Library/Python/2.7/site-packages/rest_framework/renderers.py" in <module>
20. from rest_framework import exceptions, serializers, status, VERSION
File "/Library/Python/2.7/site-packages/rest_framework/serializers.py" in <module>
1354. ModelSerializer.serializer_field_mapping[postgres_fields.HStoreField] = CharMappingField
Exception Type: AttributeError at /
Exception Value: 'module' object has no attribute 'HStoreField'
Upvotes: 3
Views: 1930
Reputation: 29967
Installing the latest release candidate of Django 1.8 should fix the issue.
You are running 1.8.dev20140910173004, which already has support for some Postgres fields, but not for HStoreField
yet. Django REST framework only checks for the django.contrib.postgres
and then assumes that HStoreField
is available too. For your version of Django that is not the case.
If pip install -u
doesn't get you the latest version, try removing and reinstalling Django.
Upvotes: 2