0

I'm trying to use django auth ldap (v1.1.7) with a custom user model and, while I have everything else taken care of, I still run into a familiar error message that I just don't know how to fix.

Running python manage.py syncdb returns:

CommandError: One or more models did not validate:
django_auth_ldap.testprofile: 'user' defines a relation with the model 'auth.Use
r', which has been swapped out. Update the relation to point at settings.AUTH_US
ER_MODEL.

My question here is - where can I find django_auth_ldap.testprofile and update the relation, to fix the issue?

Thanks in advance for helping me out.

L.E.: Ok, after a little googleing, i found out that this testprofile is located in django_auth_ldap/models.py and get this: I searched through all of my files and found the file, modified it to point to settings.AUTH_USER_MODEL and still I receive the same error.

Can anyone please help me out with this issue?

Adelin
  • 7,809
  • 5
  • 37
  • 65
  • Where is your custom user model? and what is the value of `AUTH_USER_MODEL` in settings.py? – Bibhas Debnath Jan 30 '14 at 14:20
  • My custom user model is within projects/models.py, named CustomUser (projects is the name of my app). In settings, the value of AUTH_USER_MODEL is projects.CustomUser. All other relations are fixed when I define the foreignkey to point to settings.AUTH_USER_MODEL. – Adelin Jan 30 '14 at 14:38

1 Answers1

1

This is the part of django_auth_ldap's models.py -

class TestProfile(models.Model):
    """
    A user profile model for use by unit tests. This has nothing to do with the
    authentication backend itself.
    """
    user = models.OneToOneField('auth.User')  # <-- here is the trouble
    is_special = models.BooleanField(default=False)
    populated = models.BooleanField(default=False)

You cannot fix it unless you fix this part of the code and do as said in Django documentation -

Instead of referring to User directly, you should reference the user model using django.contrib.auth.get_user_model(). This method will return the currently active User model – the custom User model if one is specified, or User otherwise.

And I wont recommend modifying the 3rd party packages yourself. If you can, go suggest the change to the developer, or send them a pull request. Once it's accepted, update the package.

Bibhas Debnath
  • 14,559
  • 17
  • 68
  • 96
  • This looks promising - keep you posted with the result – Adelin Jan 30 '14 at 14:38
  • it's strange, now I ran into error `CommandError: One or more models did not validate:` `django_auth_ldap.testprofile: 'user' has a relation with model settings.AUTH_USE` `R_MODEL, which has either not been installed or is abstract.` – Adelin Jan 30 '14 at 15:26
  • managed to get it to work. Initially i had `user = models.OneToOneField('settings.AUTH_USER_MODEL')` but i changed this to `user = get_user_model()` and it worked ok afterwards. Too bad I had to temper with 3rd party packages. Thank you very much for your help – Adelin Jan 30 '14 at 15:37
  • 1
    I'd still suggest you send a pull request to the package developer. Or else you'll have a broken dependency forever. – Bibhas Debnath Jan 30 '14 at 15:43