mercredi 3 août 2016

Django unit test fails because of related model

My Django project running 1.9.7 has a model that utilises Django user authentication to handle user accounts, permissions and sessions etc. I've done this by making a one to one relationship in my model like so:

from django.contrib.auth.models import User
class ProjectUser(models.Model):
    user=models.OneToOneField(User)

This has worked fine until I came to write my unit tests. I get the following when I execute:

python manage.py test

  File "/net/homes/priordan/work/cmpm/venv/lib/python2.7/site-packages/django/db/models/fields/related.py", line 566, in resolve_related_fields
    raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model u'myproject.User' cannot be resolved

I see many people have come across a similar error when trying to run a database migrate but I can run migrate without issues. Does anyone have any idea why this is causing errors when running unittests?

Aucun commentaire:

Enregistrer un commentaire