OperationalError 1054使用django-tagging的未知列'tags'

时间:2011-10-25 15:07:11

标签: django tagging django-tagging

我正在尝试在我的django应用程序中使用django-tagging,但插入字段时出现SQL错误

我的模型有标签= TagField()

>>> from cms.models import Articles
>>> a=Articles()
>>> a.save()
OperationalError: (1054, "Unknown column 'tags' in 'field list'")

我的数据库上是否需要“标签”文本字段? AFAIK django-tagging只用它的表来处理它(tagging_tag和tagging_taggeditem)

感谢

1 个答案:

答案 0 :(得分:1)

您是否尝试过manage.py syncdb?我建议使用tagging.register而不是在模型中声明“tags”字段:

models.py:

import tagging

class Articles(models.Model):
    ...

tagging.register(Articles)

forms.py:

from tagging.forms import TagField

class ArticlesForm(ModelForm):
    tags = TagField()

    def save(self, commit=True):
        instance = super(ArticlesForm, self).save(commit)
        instance.tags = self.cleaned_data['tags']
        return instance

    class Meta:
        model = Articles