setting中 AUTH_USER_MODEL 的问题

来源:6-3 用户登录-2

慕容909780

2018-05-03

之前设置AUTH_USER_MODEL = 'users.UserProfile' 程序没有报错 后来 不知道改了什么 突然就报错啦。


Unhandled exception in thread started by <_pydev_bundle.pydev_monkey._NewThreadStartupWithTrace instance at 0x7f104ec3ec68>

Traceback (most recent call last):

  File "/home/zxc/下载/pycharm-2018.1/helpers/pydev/_pydev_bundle/pydev_monkey.py", line 589, in __call__

    return self.original_func(*self.args, **self.kwargs)

  File "/home/zxc/.virtualenvs/mxonline/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper

    fn(*args, **kwargs)

  File "/home/zxc/.virtualenvs/mxonline/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run

    autoreload.raise_last_exception()

  File "/home/zxc/.virtualenvs/mxonline/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception

    six.reraise(*_exception)

  File "/home/zxc/.virtualenvs/mxonline/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper

    fn(*args, **kwargs)

  File "/home/zxc/.virtualenvs/mxonline/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup

    apps.populate(settings.INSTALLED_APPS)

  File "/home/zxc/.virtualenvs/mxonline/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate

    app_config.import_models(all_models)

  File "/home/zxc/.virtualenvs/mxonline/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models

    self.models_module = import_module(models_module_name)

  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module

    __import__(name)

  File "/home/zxc/.virtualenvs/mxonline/local/lib/python2.7/site-packages/django/contrib/admin/models.py", line 32, in <module>

    class LogEntry(models.Model):

  File "/home/zxc/.virtualenvs/mxonline/local/lib/python2.7/site-packages/django/contrib/admin/models.py", line 41, in LogEntry

    verbose_name=_('user'),

  File "/home/zxc/.virtualenvs/mxonline/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 750, in __init__

    RECURSIVE_RELATIONSHIP_CONSTANT,

AssertionError: ForeignKey(('users.UserProfile',)) is invalid. First parameter to ForeignKey must be either a model, a model name, or the string u'self'


写回答

1回答

bobby

2018-05-05

ForeignKey must be either a model, a model name, or the string u'self' ForeignKey的外键第一参数必须是另一个model 你应该是写错了 仔细检查一下你的所有model看看哪个model定义错了

0
6
慕容909780
回复
bobby
谢谢 老师
2018-05-09
共6条回复

Python3.6+django+xadmin,打造在线教育平台

【毕设】Python 2.7到3.6 完美适配,Django升级2.0

3677 学习 · 4038 问题

查看课程