Question

I'm making an app from Netutus http://net.tutsplus.com/tutorials/python-tutorials/building-ribbit-with-django/ and I got this error when I ran syncdb. I did some research I found I had to put an related_field in ForeignKey but I still had the error.

 Error : one or more models did not validate:
 forum.userprofile: Reverse query name for field 'user' clashes with related field 'User.userprofile'. Add a related_name argument to the definition for 'user'.

My models.py

 from django.db import models
 from django.contrib.auth.models import User
 import hashlib


 class Ribbit(models.Model):
     content = models.CharField(max_length=140)# 
     user = models.ForeignKey(User, related_name="note")
     creation_date = models.DateTimeField(auto_now=True, blank=True)

 class UserProfile(models.Model):
     user = models.OneToOneField(User)
     follows = models.ManyToManyField('self', related_name='followed_by', symmetrical=False)


 User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
Was it helpful?

Solution

Have you tried adding a related_name argument to the user field, in the UserProfile model?

user = models.OneToOneField(User, related_name='user_profile')

At least that's what the error message says.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top