5

所以我有一个名为 Profile 的扩展用户模型(扩展 AbstractUser)。这是在一个名为“个人资料”的单独应用程序中。我正在插入标准登录并意识到它正在寻找一个“配置文件”应用程序名称作为标准,所以我重命名了它(目录、代码、数据库模式),我认为它应该可以工作。app_name 实际上已经在 apps.py 中设置为“profile”,所以不需要重命名 url 引用。

没有骰子。我得到标题中的错误。

所以我删除了所有迁移(我处于我仍然可以这样做的阶段:))并删除了我目前正在使用的 sqlite DB,以为我只是重新运行迁移并重新创建所有内容。

同样的错误。

堆栈跟踪是:

λ  python manage.py makemigrations
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\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 361, in execute
    self.check()
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\apps.py", line 18, in check_middleware
    from debug_toolbar.middleware import DebugToolbarMiddleware
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\middleware.py", line 12, in <module>
    from debug_toolbar.toolbar import DebugToolbar
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 141, in <module>
    urlpatterns = DebugToolbar.get_urls()
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 134, in get_urls
    for panel_class in cls.get_panel_classes():
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 116, in get_panel_classes
    import_string(panel_path) for panel_path in dt_settings.get_panels()
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\toolbar.py", line 116, in <listcomp>
    import_string(panel_path) for panel_path in dt_settings.get_panels()
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\mjnic\.virtualenvs\pyp-E_0Se9Bl\lib\site-packages\debug_toolbar\panels\profiling.py", line 1, in <module>
    import cProfile
  File "D:\Python\Python37-32\Lib\cProfile.py", line 22, in <module>
    run.__doc__ = _pyprofile.run.__doc__
AttributeError: module 'profile' has no attribute 'run'

作为此重命名的一部分,我错过了什么?

我错过的任何其他信息会有所帮助吗?(我已经搜索了“配置文件”的任何实例,但是现在所有内容都已正确重命名,并且该应用在此之前运行正常,所以纯粹是这个重命名搞砸了)。

编辑:可能是“配置文件”与某些内部 python 例程冲突吗?python安装下的那个cProfile.py文件定义为

#! /usr/bin/env python3

"""Python interface for the 'lsprof' profiler.
   Compatible with the 'profile' module.
"""

现在这与我的项目无关?我是否只需要调用我的应用程序/扩展用户模型而不是“配置文件”?

4

2 回答 2

14

好的。所以是的,这是一个命名冲突。我已将我的“个人资料”模型和“个人资料”应用程序重命名为“UserProfile”和“user_profile”,并相应地更新了所有内容。现在一切似乎都奏效了......

只是在这里给出一个答案,以防将来有人遇到同样的问题!

于 2019-08-02T11:26:58.627 回答
10

就我而言,它是profile.py文件。

删除文件并重试。

于 2020-12-29T11:20:52.680 回答