4

I am using django to create a blog. It is installed inside a virtual environment and django-tagging has been installed. I'm doing DB migrations with south and everything seems to work ok with my migrations, but it seems the tagging tables are not being created, so when I go to add a blog post via the admin I get the famous postgresql error:

Exception Type: DatabaseError at /admin/bppsite/blogpost/add/
Exception Value: relation "tagging_tag" does not exist
LINE 1: ...ECT "tagging_tag"."id", "tagging_tag"."name" FROM "tagging_t...

Here is relevant parts of my models.py:

from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^tagging\.fields\.TagField"])

from tagging.models import Tag
from tagging.fields import TagField

class BlogPost(models.Model):
    title = models.CharField(max_length = 255)
    text = models.TextField()
    author = models.ForeignKey(User)
    created = models.DateTimeField(auto_now_add = True)
    modified = models.DateTimeField(auto_now = True)
    status = models.CharField(max_length = 10, choices=POST_STATUS_CHOICES,     default='DRAFT')
    slug = models.SlugField(max_length = 255, blank=True)
    category = models.ManyToManyField(Category)
    tags = TagField()

    def __unicode__(self):
        return self.title

    class Meta:
        ordering = ["-created"]

    def save(self):
        if not self.id:
            self.slug = slugify(self.title)
        super(BlogPost, self).save()

    def set_tags(self, tags):
        Tag.objects.update_tags(self, tags)

    def get_tags(self, tags):
        return Tag.objects.get_for_object(self)

and, installed apps from settings.py:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'south',
    'tinymce',
    'tagging',
    'bppsite',
)

I have tried moving the ordering of the apps around in INSTALLED_APPS (thinking the tagging might need to come before my app) but it doesn't seem to make any difference.

I know it's going to be something simple but can't figure it out.

thanks Aaron

4

1 回答 1

11

好的。我不敢相信它是多么简单,答案就在我面前。但是,如果其他人碰巧处于相同的位置,希望他们会偶然发现这个问题,我现在将自行回答。

这个问题与 django-tagging 无关。这与南方只会迁移我告诉它迁移的事实有关!和南一样棒(我永远不会使用没有它的 django 项目,因为我已经找到了它)——它不会迁移第三方应用程序。我曾假设南会查看我的 settings.py 并确定哪些已安装的应用程序需要与数据库同步并选择它们,就好像我只是正常运行 syncdb 一样。这不是 south 所做的,因此每个安装的第三方应用程序都需要自行迁移,以确保它存在于数据库中。所以,我所要做的就是将表放入我的数据库:

./manage.py schemamigration tagging --initial
./manage.py migrate tagging

我确信有一种方法可以将所有迁移集中在一起,但我现在可以为我的小规模的东西一个一个地做 - 很高兴有人详细说明这个答案并揭示迁移所有应用程序的最佳方法同时使用一个命令——这可能吗?

于 2012-07-16T11:54:59.660 回答