syncj时django'没有这样的表'

时间:2012-12-18 08:51:44

标签: django django-syncdb

这是我的模特:

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'

每次我运行syncdb时,都会收到错误:django.db.utils.DatabaseError: no such table: talk_basemodeltalk

我已将该应用放在我的settings.py talk上。

我真的不知道是什么导致这个,唯一的线索就是class Meta BaseModelTalk如果我评论那条线,我就没有错误。

1 个答案:

答案 0 :(得分:1)

错误原因:我们无法将模型子类化为我们在那里明确定义管理器,自定义或非自定义的模型。只需从objects中删除BaseModelTalk行,然后将其放在abstract = False将修复它的每个模型上。