请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

migrations时候报错

已经按照视频中讲到的在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 “

  1. userprofile表定义源码

https://img1.sycdn.imooc.com//szimg/60594a7e09a22ce517040494.jpg

    2. 左侧代码导航结构

https://img1.sycdn.imooc.com//szimg/60594a9609aecbf905860633.jpg

    3. users下的apps.py源码

https://img1.sycdn.imooc.com//szimg/60594aab097b8dbe10600397.jpg

    4. install_apps的配置

https://img1.sycdn.imooc.com//szimg/60594ac10950b05e07400415.jpg


正在回答

2回答

将下面的内容截图我看看:

    1. userprofile表定义源码

    2. 左侧代码导航结构

    3. users下的apps.py源码

    4. install_apps的配置

0 回复 有任何疑惑可以回复我~
  • 提问者 Essence_CC #1
    已经添加到提问部分了,麻烦老师帮忙看下
    回复 有任何疑惑可以回复我~ 2021-03-23 09:57:22
  • 提问者 Essence_CC #2
    问题已基本解决,谢谢老师,不用看了
    回复 有任何疑惑可以回复我~ 2021-03-23 11:14:38
  • 提问者 Essence_CC #3
    非常感谢!
    回复 有任何疑惑可以回复我~ 2021-03-23 16:36:57
提问者 Essence_CC 2021-03-23 11:02:34

今天重新试了一下,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.


0 回复 有任何疑惑可以回复我~
  • 提问者 Essence_CC #1
    在网页上查到下面这个解决方法 migrate后正常了
    ----------------------------------------------------------------------
    进入site-packages/django/contrib/admin/migrations文件目录下,除了__init__.py文件,其他的全部删除。
    回复 有任何疑惑可以回复我~ 2021-03-23 11:13:51
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信