我正在从 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'.
我的模型.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])