0
我從Netutus http://net.tutsplus.com/tutorials/python-tutorials/building-ribbit-with-django/製作應用程序,當我運行syncdb時出現此錯誤。我做了一些研究,發現我必須在ForeignKey中放入一個related_field,但我仍然有錯誤。Django錯誤:一個或多個模型沒有驗證:
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])
我要去閱讀這個related_field的文檔,下次仔細閱讀整個語法。謝謝你mariano – donkeyboy72 2013-02-27 15:20:58
不客氣。事實上,感謝_you_我的第一個被接受的答案 – Mariano 2013-02-27 15:22:01