Question

Here's my model:

class BaseModelTalk(models.Model):

    name            = models.CharField('Name', max_length = 100)
    slug            = models.SlugField('Slug', blank = True)
    creator         = models.ForeignKey('person.Person')
    date_created    = models.DateTimeField(default = now)
    objects         = CustomTalkManager()

    class Meta:
        abstract = True

    def save(self, *args, **kwargs):
        if not self.id:
            self.slug = slugify(self.name)
        super(BaseModelTalk, self).save(*args, **kwargs)

    def __unicode__(self):
        return u'%s' % self.slug

class Talk(BaseModelTalk):

    tags            = TaggableManager()
    description     = models.TextField('Talk description')

    class Meta:
        verbose_name = 'Talk'
        verbose_name_plural = 'Talks'

class ThreadTextRating(RatedItemBase):
    content_object = models.ForeignKey('talk.ThreadText')

class ThreadImageRating(RatedItemBase):
    content_object = models.ForeignKey('talk.ThreadImage')

class ThreadLinkRating(RatedItemBase):
    content_object = models.ForeignKey('talk.ThreadLink')

class Thread(BaseModelTalk):

    THREAD_TYPE = (('text', 'Text'),
                   ('image', 'Image'),
                   ('link', 'Link'))

    type            = models.CharField('Thread\'s type', max_length = 5, choices = THREAD_TYPE, blank = True, null = True)

    class Meta:
        abstract = True

class ThreadText(Thread):

    ratings         = Ratings(ThreadTextRating)
    talk            = models.ForeignKey('talk.Talk', related_name = 'text_threads')
    content         = models.TextField('Thread\'s context')

    class Meta:
        verbose_name = 'Text'
        verbose_name_plural = 'Text\'s'  

class ThreadImage(Thread):

    ratings         = Ratings(ThreadImageRating)
    talk            = models.ForeignKey('talk.Talk', related_name = 'image_threads')
    image           = ImageField('Thread\'s image', upload_to = 'thread/image/')

    class Meta:
        verbose_name = 'Image'
        verbose_name_plural = 'Image\'s'

class ThreadLink(Thread):

    ratings         = Ratings(ThreadLinkRating)
    talk            = models.ForeignKey('talk.Talk', related_name = 'link_threads')
    link            = models.URLField('Thread\'s link')

    class Meta:
        verbose_name = 'Link'
        verbose_name_plural = 'Link\'s'

Everytime i run syncdb, i got an error : django.db.utils.DatabaseError: no such table: talk_basemodeltalk.

I already put the app on my settings.py which is talk.

I really have no idea what cause this, the only clue is the class Meta on BaseModelTalk which if i comment that line, i got no error.

Was it helpful?

Solution

Reason of the error : We cannot subclass a model where we explicitly define a manager there, custom or non-custom. Simply by removing the objects line from BaseModelTalk and place it on each model where abstract = False will fix it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top