Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

south not creating tables for third party installed app

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

like image 576
Alpaus Avatar asked Dec 21 '22 19:12

Alpaus


1 Answers

OK. I can't believe how simple it was, the answer was right there in front of my face. However, if anyone else happens to be in the same position, hopefully they will stumble across this question which I will now self-answer.

The issue is nothing to do with django-tagging. It is to do with the fact that south will only migrate what I tell it to migrate! As awesome as south is (I will never use a django project without it now that I've found it) – it doesn't migrate the third party apps. I had assumed south would look into my settings.py and work out which installed apps needed to be synced with the database and just pick them up, as if I were just running syncdb as normal. This is not what south does, so each third party app installed needs to be migrated on its own to ensure it exists in the database. So, all I had to do to get the tables into my database:

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

I'm sure there is a way to lump all of the migrations together but I'm ok doing them one by one for my small scale stuff for now – happy for someone to elaborate on this answer and reveal the best way to migrate all apps at the same time with a single command – is it possible?

like image 172
Alpaus Avatar answered Jan 05 '23 19:01

Alpaus