Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
557 views
in Technique[技术] by (71.8m points)

python - Django syncdb error: One or more models did not validate

/mysite/project4

 class notes(models.Model):
   created_by = models.ForeignKey(User)
   detail = models.ForeignKey(Details) 

Details and User are in the same module i.e,/mysite/project1 In project1 models i have defined

   class User():
      ......

   class Details():
      ......

When DB i synced there is an error saying

Error: One or more models did not validate: project4: Accessor for field 'detail' clashes with related field . Add a related_name argument to the definition for 'detail'.

How can this be solved..

thanks..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Gee we just had this one; and I answered...

You have a number of foreign keys which django is unable to generate unique names for.

You can help out by adding "related_name" arguments to the foreignkey field definitions in your models. Eg:

 class notes(models.Model):
    created_by = models.ForeignKey(User, related_name="note_created_by_user")
    detail = models.ForeignKey(Details, related_name="noted_and_detailed")

See here for more. http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.related_name


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...