ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models'
See original GitHub issueTried to install the package with all requirements and following the steps described in README resulted in the following error when migrating:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "<env_dir>/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "<env_dir>/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "<env_dir>/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "<env_dir>/lib/python3.8/site-packages/django/apps/registry.py", line 122, in populate
app_config.ready()
File "<env_dir>/lib/python3.8/site-packages/django/contrib/admin/apps.py", line 24, in ready
self.module.autodiscover()
File "<env_dir>/lib/python3.8/site-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "<env_dir>/lib/python3.8/site-packages/django/utils/module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<env_dir>/lib/python3.8/site-packages/advanced_filters/admin.py", line 10, in <module>
from .forms import AdvancedFilterForm
File "<env_dir>/lib/python3.8/site-packages/advanced_filters/forms.py", line 13, in <module>
from django.db.models import Q, FieldDoesNotExist
ImportError: cannot import name 'FieldDoesNotExist' from 'django.db.models' (<env_dir>/lib/python3.8/site-packages/django/db/models/__init__.py)
Steps:
1-) pip install django-advanced-filters
Output:
Collecting django-advanced-filters
Downloading django_advanced_filters-1.2.0-py3-none-any.whl (68 kB)
|ββββββββββββββββββββββββββββββββ| 68 kB 704 kB/s
Collecting django-braces<1.14.0,>=1.4.0
Downloading django_braces-1.13.0-py2.py3-none-any.whl (15 kB)
Collecting simplejson<4,>=3.6.5
Downloading simplejson-3.17.2-cp38-cp38-manylinux2010_x86_64.whl (137 kB)
|ββββββββββββββββββββββββββββββββ| 137 kB 2.3 MB/s
Installing collected packages: django-braces, simplejson, django-advanced-filters
Successfully installed django-advanced-filters-1.2.0 django-braces-1.13.0 simplejson-3.17.2
2-) added django-advanced-filters to projects settings.py;
3-) python manage.py makemigrations
Output:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "<env_dir>/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "<env_dir>/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "<env_dir>/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "<env_dir>/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "<env_dir>/lib/python3.8/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<env_dir>/lib/python3.8/site-packages/advanced_filters/models.py", line 6, in <module>
from .q_serializer import QSerializer
File "<env_dir>/lib/python3.8/site-packages/advanced_filters/q_serializer.py", line 6, in <module>
import six
ModuleNotFoundError: No module named 'six'
4-) pip install six
Output:
Collecting six
Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Installing collected packages: six
Successfully installed six-1.15.0
5-) added six to projects settings.py;
6-) python manage.py makemigrations
and python manage.py migrate
outputs the first described exception.
7-) added simplejson to projects settings.py;
π python manage.py makemigrations
and python manage.py migrate
also outputs the first described exception.
9-) removed six and simplejson from projects settings.py;
10-) python manage.py makemigrations
and python manage.py migrate
also outputs the first described exception.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (2 by maintainers)
Top GitHub Comments
this is occurred because we use django 3.1
EDIT: My fix proposed below has already been implemented in the develop branch of this repo. Dβoh!
@asfaltboy I think this could easily be fixed by using
from django.core.exceptions import FieldDoesNotExist
β¦instead ofβ¦
from django.db.models import Q, FieldDoesNotExist
β¦in forms.py.
Itβs mentioned in the release notes for 3.1:
The move of the exception was made in 2015, which would correspond to Django 1.x, so I think it should be safe to use the new import! π