django報錯:ValueError: Lookup failed for model referenced by field

django版本:

>>> django.get_version()

'1.8.16'

報錯:

E:\python_project\travel>python manage.py makemigrations

Traceback (most recent call last):? File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\apps\config.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:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\migrations\state.py", line 238, in __init__? ? model = self.get_model(lookup_model[0], lookup_model[1])? File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\apps\registry.py", line 202, in get_model? ? return self.get_app_config(app_label).get_model(model_name.lower())? File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\apps\config.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:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line

utility.execute()

File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\__init__.py", line 346, in execute

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

File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv

self.execute(*args, **cmd_options)

File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\base.py", line 445, in execute

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

File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\commands\makemigrations.py", line 125, in handle

migration_name=self.migration_name,

File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\migrations\autodetector.py", line 43, in changes

changes = self._detect_changes(convert_apps, graph)

File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\migrations\autodetector.py", line 110, in _detect_changes

self.old_apps = self.from_state.concrete_apps

File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\migrations\state.py", line 170, in concrete_apps

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

File "C:\Users\Acer\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\migrations\state.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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容