[Django]-MakeMigration Error on Django – ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models'

26👍

Your version of django-allauth has the incorrect import for FieldDoesNotExist. The correct import is:

from django.core.exceptions import FieldDoesNotExist

The import from django.db.models presumably worked in older versions of Django.

The import was fixed in django-allauth in version 0.41.0. If you update django-allauth in your requirements.txt or pipenv it should fix the problem.

21👍

In my case, Django version 3.1.3 conflicted with django-filter 2.0.0.

Similar error message. But the last lines of error said that it was graphene-django. However, in the middle, it says django-filter. When I looked into the django-filter source file, there was a wrong import of FieldDoesNotExist. When I upgrade django-filter to version 2.4.0, problem solved.

👤Si Thu

2👍

In OP’s case it was django-allauth, in my case django-filter.

Check the last line in error log that shows the file in which from django.db.models import FieldDoesNotExist, FileField is imported and try upgrading that package.

In OP’s case the error log line was this:

File "/usr/local/lib/python3.7/site-packages/allauth/utils.py"...

👤kater

1👍

As I can see you have version 3.0.8.
But for me, it helped when I changed requirements.txt from Django>=3.0.6(used latest 3.1 Docker image) to Django==3.0.6 as I was using the latest 3.1 version where it seems to be an issue with compatibility on 3rd party packages.

👤aer_0

1👍

My error log showed that the error was coming from the rest_framework app
(File "/home/Username_here/restapi-basics/lib/python3.8/site-packages/
rest_framework/serializers.py", line 25, in ). But I couldn’t upgrade it (as specified in the solutions above) since it was just an app I had added to my Django project.

What worked for me was upgrading all the packages in my virtual environment using pip. Here’s the command I used:

pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U

Source: How to upgrade all Python packages with pip

0👍

I faced a similar issue cannot import name 'FieldDoesNotExist' from 'django.db.models.fields' and this time issue was with mismatch djangorestframework with the base Django version

I was using djangorestframework 3.7.3 with Django 3.2.15, which was later resolved by upgrading djangorestframework 3.11.0 using

pip install djangorestframework==3.11.0

So in case anyone is facing such an issue, it’s better to check the various django component compatibility

👤Sam

Leave a comment