Pergunta

I' currently doing django from some video tutorial. I had difficult to figure out the line which forces to following error.

Validating models...

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0xb6e5722c>>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 253, in validate
raise CommandError("One or more models did not validate:\n%s" % error_text)
django.core.management.base.CommandError: One or more models did not validate:
events.event: 'attendees' specifies an m2m relation through model Attendence, which has not been installed

I had include source code at bitbucket.

Foi útil?

Solução

In models.ManyToManyField() of Event class I had put wrong name on through which causes the problem. Later I fixed it with correct class name and problem solved.

After correcting error model.py look like

...
class Event(models.Model): ##error
    #"""docstring for Event"""
    description = models.TextField()
    creation_date = models.DateTimeField(default = datetime.now) #if you put the parenthesis on datetime.now every time changing the date called new function with different date and time
    start_date = models.DateTimeField(null = True,blank = True)
    creator = models.ForeignKey(User,related_name='event_creator_set')
    attendees = models.ManyToManyField(User,through='Attendance') #error occurs due to wrong class name on through
    latest = models.BooleanField(default = True)

    objects = EventManager()
    def __unicode__(self):
        return self.description

    def save(self,**kwargs):
        Event.objects.today().filter(latest=True,
            creator=self.creator).update(latest=False)
        super(Event,self).save(**kwargs)

class  Attendance(models.Model): ##error
    user = models.ForeignKey(User)#,related_name='attendance_user_set')
    event = models.ForeignKey(Event)#,related_name='attendance_event_set') ###error
    registration_date = models.DateTimeField(default=datetime.now)

    def __unicode__(self):
        return "%s is attending %s" %(self.user.username,self.event)
...

Also Django syncdb error: One or more models did not validate suggested me to add related_name but excluding it don't cause any error so I hadn't include this.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top