我正在从Netutus http://net.tutsplus.com/tutorials/python-tutorials/building-ribbit-with-django/制作应用程序,当我运行syncdb时出现此错误。我做了一些研究,我发现我必须在ForeignKey中放入一个related_field,但我仍然有错误。
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'.
我的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])
答案 0 :(得分:2)
您是否尝试在UserProfile模型的用户字段中添加related_name参数?
user = models.OneToOneField(User, related_name='user_profile')
至少这是错误信息所说的内容。