On Fri, Jul 10, 2009 at 5:54 PM, sjtirtha <sjtir...@gmail.com> wrote:

> Hi,
>
> I have a problem calling manage.py syncdb for my models.
> Here is my models:
> from django.db import models
> from django.contrib.auth.models import User
>
> # Create your models here.
> class DocumentType(models.Model):
>     name         = models.CharField(max_length=20, unique=True)
>     description  = models.CharField(max_length=200)
>     assignedType = models.ForeignKey('self')
>
> class Category(models.Model):
>     name    = models.CharField(max_length=20, unique=True)
>     type    = DocumentType()
>     relatedCategories = models.ForeignKey('self',
> related_name='relatedCategories')
>     description  = models.CharField(max_length=200)
>
> class Document(models.Model):
>     type             = DocumentType()
>     viewed           = models.PositiveIntegerField(max_length=7)
>     #rating           =
>     #ranking          =
>     created_by       = User()
>     changed_by       = User()
>     created_at       = models.DateTimeField()
>     changed_at       = models.DateTimeField()
>     categories        = models.ManyToManyField(Category,
> related_name='categories')      #n to m relationship
>     assignedDocuments = models.ForeignKey('self',
> related_name='assignedDocuments')
>     parentDocument = models.ForeignKey('self',
> related_name='parentDocument')    #1 to n relationship
>
> The error that I got is:
> Error: One or more models did not validate:
> common.category: Accessor for field 'relatedCategories' clashes with field
> 'Category.relatedCategories'. Add a related_name argument to the definition
> for 'relatedCategories'.
> common.category: Reverse query name for field 'relatedCategories' clashes
> with field 'Category.relatedCategories'. Add a related_name argument to the
> definition for 'relatedCategories'.
> common.document: Accessor for field 'assignedDocuments' clashes with field
> 'Document.assignedDocuments'. Add a related_name argument to the definition
> for 'assignedDocuments'.
> common.document: Reverse query name for field 'assignedDocuments' clashes
> with field 'Document.assignedDocuments'. Add a related_name argument to the
> definition for 'assignedDocuments'.
> common.document: Accessor for field 'parentDocument' clashes with field
> 'Document.parentDocument'. Add a related_name argument to the definition for
> 'parentDocument'.
> common.document: Reverse query name for field 'parentDocument' clashes with
> field 'Document.parentDocument'. Add a related_name argument to the
> definition for 'parentDocument'.
>
> What is wrong with my model.
>

You have related name conflicts. Read about it in the docs:
http://docs.djangoproject.com/en/dev/topics/db/models/#be-careful-with-related-name

Hope that helps,

Mn

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to