【问题标题】:OperationalError 1054 Unknown column 'tags' using django-taggingOperationalError 1054 Unknown column 'tags' using django-tagging
【发布时间】:2011-10-25 15:07:11
【问题描述】:

我正在尝试在我的 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)处理它

谢谢

【问题讨论】:

    标签: django tagging django-tagging


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2018-09-10
      • 2011-03-16
      • 1970-01-01
      • 1970-01-01
      • 2020-10-13
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多