migrations时候报错
来源:7-3 自定义userprofile表覆盖默认的user表
Essence_CC
2021-03-22
已经按照视频中讲到的在settings中加上了AUTH_USER_MODEL = "users.UserProfile"
但还是在迁移数据库文件时报错 ,不知道是哪里的问题
Traceback (most recent call last):
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\config.py”, line 178, in get_
model
return self.models[model_name.lower()]
KeyError: ‘userprofile’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\auth_init_.py”, line 16
5, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\registry.py”, line 210, in ge
t_model
return app_config.get_model(model_name, require_ready=require_ready)
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\config.py”, line 181, in get_
model
"App ‘%s’ doesn’t have a ‘%s’ model." % (self.label, model_name))
LookupError: App ‘users’ doesn’t have a ‘UserProfile’ model.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “manage.py”, line 21, in
main()
File “manage.py”, line 17, in main
execute_from_command_line(sys.argv)
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management_init_.py”, line
381, in execute_from_command_line
utility.execute()
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management_init_.py”, line
357, in execute
django.setup()
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django_init_.py”, line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\registry.py”, line 122, in po
pulate
app_config.ready()
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\admin\apps.py”, line 24, i
n ready
self.module.autodiscover()
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\admin_init_.py”, line 2
6, in autodiscover
autodiscover_modules(‘admin’, register_to=site)
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\module_loading.py”, line 47,
in autodiscover_modules
import_module(’%s.%s’ % (app_config.name, module_to_search))
File “C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\importlib_init_.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “
userprofile表定义源码
2. 左侧代码导航结构
3. users下的apps.py源码
4. install_apps的配置
2回答
-
将下面的内容截图我看看:
1. userprofile表定义源码
2. 左侧代码导航结构
3. users下的apps.py源码
4. install_apps的配置
042021-03-23 -
Essence_CC
提问者
2021-03-23
今天重新试了一下,makemigrations成功创建了UserProfile,但是migrate继续报错 下面是报错内容
E:\djangoProject\myweb>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, poem, sessions, users
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line
381, in execute_from_command_line
utility.execute()
File "C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line
375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 323
, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 364
, in execute
output = self.handle(*args, **options)
File "C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 83,
in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\migrate.p
y", line 191, in handle
pre_migrate_apps = pre_migrate_state.apps
File "C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 80, in
__get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\state.py", line 210,
in apps
return StateApps(self.real_apps, self.models)
File "C:\Users\华硕\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\state.py", line 280,
in __init__
raise ValueError("\n".join(error.msg for error in errors))
ValueError: The field admin.LogEntry.user was declared with a lazy reference to 'users.userprofile', but app 'users' isn
't installed.
012021-03-23
相似问题