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