Yoga
Yoga

Reputation: 23

ImportError: Cannot import name 'DurationField'

I am trying to run an application that uses django (version 1.6.5) rest framework ( python version 3.4.5 ) .However I am getting the Import error "cannot import name DurationField".How do I resolve this error ?

File "/usr/src/app/Lab/models.py", line 8, in <module>
    from Lab import logic, common <br>
  File "/usr/src/app/Lab/logic.py", line 16, in <module>
    from Rest import viewsAppComm <br>
  File "/usr/src/app/Rest/viewsAppComm.py", line 7, in <module>
    from rest_framework.response import Response <br>
  File "/usr/local/lib/python3.4/site-packages/rest_framework/response.py", line 13, in <module>
    from rest_framework.serializers import Serializer
  File "/usr/local/lib/python3.4/site-packages/rest_framework/serializers.py", line 19, in <module>
    from django.db.models import DurationField as ModelDurationField <br>
ImportError: cannot import name 'DurationField'

Upvotes: 2

Views: 2381

Answers (1)

solarissmoke
solarissmoke

Reputation: 31404

DurationField was added in Django 1.8. You are using Django 1.6, hence the error.

Your options are to upgrade (which is a good idea if you can, because Django 1.6 has reached end of life quite a while ago) or to downgrade to an older version of Django Rest Framework (the version you currently have is not compatible with Django 1.6).

You may also be able to install the third-party django-duration-field app and then import it with:

from durationfield.db.models.fields.duration import DurationField

... but from the stack trace you posted it looks like it is DRF that is trying to import the model.

Upvotes: 4

Related Questions