Django 1.6 AbstractUser m2m模型验证错误

men*_*gen 6 python django validation django-models

我没有Django 1.5.4(稳定版)的错误,但是当我从官方tar.gz测试我的Django 1.6 beta 4上的应用程序时,我在启动时遇到了验证模型的错误.


models.py

from django.contrib.auth.models import AbstractUser, User

class ShopUser(AbstractUser):
    model_car = models.CharField(max_length=200)
    date_car = models.DateField()
    description = models.TextField(blank=True, db_index=True)

    manager = models.ForeignKey(User)
Run Code Online (Sandbox Code Playgroud)

这是manage.py runserver控制台日志:

Validating models...

Unhandled exception in thread started by <function wrapper at 0x2d941b8>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 93, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 97, in inner_run
    self.validate(display_num_errors=True)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 312, in validate
    raise CommandError("One or more models did not validate:\n%s" % error_text)
django.core.management.base.CommandError: One or more models did not validate:

adminka.shopuser: Accessor for m2m field 'groups' clashes with related m2m field 'Group.user_set'. Add a related_name argument to the definition for 'groups'.
adminka.shopuser: Accessor for m2m field 'user_permissions' clashes with related m2m field 'Permission.user_set'. Add a related_name argument to the definition for 'user_permissions'.
auth.user: Accessor for m2m field 'groups' clashes with related m2m field 'Group.user_set'. Add a related_name argument to the definition for 'groups'.
auth.user: Accessor for m2m field 'user_permissions' clashes with related m2m field 'Permission.user_set'. Add a related_name argument to the definition for 'user_permissions'.
Run Code Online (Sandbox Code Playgroud)
  • python -c"import django; print django.get_version()"
    1.6b4

需要做些什么才能解决这个问题?

jor*_*gos 15

您必须在settings.py上声明AUTH_USER_MODEL.在你的情况下:

AUTH_USER_MODEL = 'your_app.ShopUser'
Run Code Online (Sandbox Code Playgroud)

  • 没有正确记录,即使您使用的是AbstractUser而不是AbstractBaseUser,也需要此设置.https://code.djangoproject.com/ticket/19049#no2 (2认同)