Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.6 AbstractUser m2m models validation error

I don't have errors with Django 1.5.4 (stable), but when I was testing my application on Django 1.6 beta 4 from official tar.gz I got error with validation models on startup.


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)

This is manage.py runserver console log:

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'.
  • python -c "import django;print django.get_version()"
    1.6b4

What need to do for solve this problem?

like image 641
menangen Avatar asked Oct 01 '13 15:10

menangen


2 Answers

You must declare AUTH_USER_MODEL on your settings.py. In your case:

AUTH_USER_MODEL = 'your_app.ShopUser'
like image 158
jordiburgos Avatar answered Sep 21 '22 05:09

jordiburgos


For me this was fixed in Django 1.6.5 by changing this:

from django.contrib.auth.models import AbstractUser

class CustomUser(AbstractUser):
    pass

to this:

from django.contrib.auth.models import AbstractBaseUser

class CustomUser(AbstractBaseUser):
    pass

No other changes needed in Django 1.6.5. @Stormlifter's suggestion has merit but I am using this CustomUser with this stuff for OAuth2 via python-social-auth:

$ pip freeze
Django==1.6.5
Markdown==2.4.1
MySQL-python==1.2.5
PyJWT==0.2.1
South==1.0
basicauth==0.2
boto==2.28.0
django-filter==0.7
django-guardian==1.2.0
django-storages==1.1.8
djangorestframework==2.3.14
httplib2==0.9
oauth2==1.5.211
oauthlib==0.6.3
python-memcached==1.53
python-oauth2==0.7.0
python-openid==2.2.5
python-social-auth==0.2.1
requests==2.4.1
requests-oauthlib==0.4.1
shortuuid==0.4.2
six==1.7.2
wsgiref==0.1.2

My new CustomUser will be doing more than the default user and does need to be the AUTH_USER_MODEL='myapp.CustomUser' in settings.py as @jordiburgos suggested.

I hope this helps!

like image 22
e.thompsy Avatar answered Sep 24 '22 05:09

e.thompsy