django版本:

django.get_version()

‘1.8.16’

报错:

E:python_projecttravel>python manage.py makemigrations

Traceback (most recent call last):  File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangoappsconfig.py”, line 159, in get_model    return self.models[model_name.lower()]KeyError: ‘common.models.user’During handling of the above exception, another exception occurred:Traceback (most recent call last):  File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsstate.py”, line 238, in init    model = self.get_model(lookup_model[0], lookup_model[1])  File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangoappsregistry.py”, line 202, in get_model    return self.get_app_config(app_label).get_model(model_name.lower())  File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangoappsconfig.py”, line 162, in get_model    “App ‘%s’ doesn’t have a ‘%s’ model.” % (self.label, model_name))LookupError: App ‘travel_list’ doesn’t have a ‘common.models.user’ model.During handling of the above exception, another exception occurred:Traceback (most recent call last):  File “manage.py”, line 22, inexecute_from_command_line(sys.argv)

File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagement__init__.py”, line 354, in execute_from_command_line

utility.execute()

File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagement__init__.py”, line 346, in execute

self.fetch_command(subcommand).run_from_argv(self.argv)

File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagementbase.py”, line 394, in run_from_argv

self.execute(*args, **cmd_options)

File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagementbase.py”, line 445, in execute

output = self.handle(*args, **options)

File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagementcommandsmakemigrations.py”, line 125, in handle

migration_name=self.migration_name,

File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsautodetector.py”, line 43, in changes

changes = self._detect_changes(convert_apps, graph)

File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsautodetector.py”, line 110, in _detect_changes

self.old_apps = self.from_state.concrete_apps

File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsstate.py”, line 170, in concrete_apps

self.apps = StateApps(self.real_apps, self.models, ignore_swappable=True)

File “C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsstate.py”, line 248, in init

raise ValueError(msg.format(field=operations[0][1], model=lookup_model))

ValueError: Lookup failed for model referenced by field travel_list.TravelList.employer: travel_list.common.models.User

解决办法:

删除travel_list这个app下面的所有数据库,以及migrations包下面除了init.py之外的所有文件,重新运行:

python manager.py makemigrations

python manager.py migrate

文章来源于互联网,如有雷同请联系站长删除:django报错:ValueError: Lookup failed for model referenced by field

发表评论