from django.db.models.fields import FieldDoesNotExist
错误代码如下:
Traceback (most recent call last):
File "../../manage.py", line 15, in
execute_from_command_line(sys.argv)
File "C:virtualenvslfobjlibsite-packagesdjangocoremanagement_init_.py", line 401, in execute_from_command_line
utility.execute()
File "C:virtualenvslfobjlibsite-packagesdjangocoremanagement_init_.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:virtualenvslfobjlibsite-packagesdjangocoremanagementase.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:virtualenvslfobjlibsite-packagesdjangocoremanagementase.py", line 368, in execute
self.check()
File "C:virtualenvslfobjlibsite-packagesdjangocoremanagementase.py", line 396, in check
databases=databases,
File "C:virtualenvslfobjlibsite-packagesdjangocorechecks
egistry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:virtualenvslfobjlibsite-packagesdjangocorechecksurls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:virtualenvslfobjlibsite-packagesdjangocorechecksurls.py", line 23, in check_resolver
return check_method()
File "C:virtualenvslfobjlibsite-packagesdjangourls
esolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:virtualenvslfobjlibsite-packagesdjangoutilsfunctional.py", line 48, in get
res = instance.dict[self.name] = self.func(instance)
File "C:virtualenvslfobjlibsite-packagesdjangourls
esolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:virtualenvslfobjlibsite-packagesdjangoutilsfunctional.py", line 48, in get
res = instance.dict[self.name] = self.func(instance)
File "C:virtualenvslfobjlibsite-packagesdjangourls
esolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "d:python36libimportlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "
File "
File "
File "
File "
File "
File "C:UsersmaynDesktopluffyluffyapiluffyapiurls.py", line 22, in
path('home/', include('home.urls')),
File "C:virtualenvslfobjlibsite-packagesdjangourlsconf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "d:python36libimportlib_init
return _bootstrap._gcd_import(name[level:], package, level)
File "
File "
File "
File "
File "
File "
File "C:UsersmaynDesktopluffyluffyapiluffyapiappshomeurls.py", line 20, in
from . import views
File "C:UsersmaynDesktopluffyluffyapiluffyapiappshomeviews.py", line 2, in
from rest_framework.generics import ListAPIView
File "C:virtualenvslfobjlibsite-packages
est_frameworkgenerics.py", line 9, in
from rest_framework import mixins, views
File "C:virtualenvslfobjlibsite-packages
est_frameworkmixins.py", line 8, in
from rest_framework.response import Response
File "C:virtualenvslfobjlibsite-packages
est_framework
esponse.py", line 11, in
from rest_framework.serializers import Serializer
File "C:virtualenvslfobjlibsite-packages
est_frameworkserializers.py", line 24, in
from django.db.models.fields import FieldDoesNotExist
ImportError: cannot import name 'FieldDoesNotExist'
问题原因:
一开始装的是django2.0.7,然后安装pip install django-cors-headers,未指定版本,结果安装了最新版3.5,且自动把django升到了3.5版本,然而无论是启动项目,还是迁移数据库,都报错.
解决办法:
把django3.5卸了,装回2.0.7,重新安装django-cors-headers的3.1版本.然后就好了.
总结:
版本适配问题.