Django的.用户模型问题 [英] Django. Problems with User model
问题描述
将项目从Django 1.6更新到Django 1.8时出现问题
I got problem when updated project from django 1.6 to django 1.8
我有模型资料
class Profile(AbstractUser):
middle_name = models.CharField(max_length=70, blank=True, verbose_name=_("Middle name"))
gender = models.CharField(max_length=2, choices=GENDER_CHOICES)
phone = models.CharField(max_length=150, blank=True, verbose_name=_("Phone"))
status = models.CharField(max_length=500, blank=True, verbose_name=_("Status"))
education = models.CharField(max_length=350, blank=True, verbose_name=_("Education"))
progress_display = models.BooleanField(default=True, blank=True, verbose_name=_("Display progress"))
about = models.TextField(blank=True, verbose_name=_("description about"))
city = models.CharField(max_length=75, blank=True, verbose_name=_("City"))
current_city = models.CharField(max_length=75, blank=True, verbose_name=_("Current city"))
birth = models.DateTimeField(blank=True, null=True, verbose_name=_("Birthday"))
registered = models.DateTimeField(auto_now=True, help_text=_('Registration date'),
verbose_name=_("registration date"))
is_teacher = models.BooleanField(default=False, blank=True, verbose_name=_("is_teacher"))
hide_fields = models.CharField(max_length=255, blank=True)
subscription = models.BooleanField(default=False, blank=True, verbose_name='Подписка на рассылку')
main_photo = models.ForeignKey('avatar.Photo', blank=True, verbose_name=_("user main-photo"), related_name='avatar', default=None, null=True)
class Meta:
verbose_name = _('User')
verbose_name_plural = _('Users')
ordering = ('-registered', 'id')
get_latest_by = 'registered'
我的应用程序位于单独的文件夹(应用程序")中.我在这样的设置中定义的文件夹的路径:
My applications are located in separated folder ("applications"). path to folder i define in settings like this:
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.join(BASE_DIR, 'applications'))
我还在设置(位于Profile应用程序中)中定义了我的自定义用户模型
I also define my custom User-model in settings (located in Profile application)
AUTH_USER_MODEL = 'profile.Profile'
这是我的安装应用程序
INSTALLED_APPS = (
'social',
'photo',
'profile',
'qa',
'main',
'learn',
'donate',
'notifications',
'articles',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.contenttypes',
'grappelli',
'django_extensions',
'django.contrib.admin',
'rest_framework',
'djkombu',
'autofixture',
'crispy_forms'
)
"runserser"命令,"makemigrations"或"migrate"命令运行良好,但createsuperuser返回此命令
commands "runserser", 'makemigrations' or 'migrate' work good but createsuperuser return this
Traceback (most recent call last):
File "/opt/pycharm-3.0.2/helpers/pycharm/django_manage.py", line 23, in <module>
run_module(manage_file, None, '__main__', True)
File "/usr/lib/python2.7/runpy.py", line 176, in run_module
fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/camaro/programming/imedrese/master/manage.py", line 14, in <module>
execute_from_command_line(sys.argv)
File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 190, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 41, in load_command_class
return module.Command()
File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 28, in __init__
self.UserModel = get_user_model()
File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 155, in get_user_model
"AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'profile.Profile' that has not been installed
推荐答案
我的声誉不足以对您的问题发表评论,因此即使它不能回答您的问题,我也将其放在此处作为答案.
My reputation is insufficient to comment on your question, so I put this here as answer, even if it doesn't answer your question.
根据 docs 扩展 User
-model时,您的方法似乎-抱歉-错误.据我从您的代码中看到的那样,除了向帐户添加更多信息之外,您对个人资料
并没有做任何特别的事情.可以使用与原始Django用户的 OneToOne
关系(如链接文档中所述)来完成.
According to the docs on extending the User
-model, your approach seems - sorry - wrong. As far as I can see from your code, you're not doing anything special with your Profile
, except from adding more information to an account. This can be done using a OneToOne
-relation with the original Django User (as described in the linked documentation).
那是说:我不明白为什么您的模型在升级到1.8时为什么应该停止工作.您是否已检查 1.7发行说明或
That said: I can't see why your model should stop working when upgrading to 1.8. Have you checked the 1.7 release notes or 1.8 release notes, if they have changed anything regarding custom User-models?
这篇关于Django的.用户模型问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!