Django-1.7中的django-taggit错误:'tags'与模型<class'taggit.models.tag'=“”> </class>有m2m关系

时间:2014-01-12 07:06:40

标签: python django django-1.7 django-migrations

我写过一个我在Django-1.7中制作的BlogEntry模型

当我跑/manage.py makemigration时,我收到以下错误。

CommandError: One or more models did not validate:
blog.blogentry: 'tags' has an m2m relation with model <class 'taggit.models.Tag'>, which has either not been installed or is abstract.

我无法弄清楚究竟是什么问题。有人可以帮忙吗?

代码:

class BlogEntry(models.Model):    
    title = models.CharField(max_length=100)
    slug = models.SlugField()
    text = MarkupField(default_markup_type=getattr(settings,
                                                   'DEFAULT_MARKUP_TYPE',
                                                   'plain'),
                       markup_choices=getattr(settings, "MARKUP_RENDERERS",
                                              DEFAULT_MARKUP_TYPES))
    summary = models.TextField()
    created_on = models.DateTimeField(default=datetime.max, editable=False)
    created_by = models.ForeignKey(User, unique=False)
    is_page = models.BooleanField(default=False)
    is_published = models.BooleanField(default=True)
    published_date = models.DateTimeField()
    comments_allowed = models.BooleanField(default=True)
    is_rte = models.BooleanField(default=False)

    meta_keywords = models.TextField(blank=True, null=True)
    meta_description = models.TextField(blank=True, null=True)

    tags = TaggableManager()

    default = models.Manager()
    objects = BlogPublishedManager()

修改:如果我将'taggit添加到INSTALLED_APPS,我会针对上述相同代码收到此错误。

/usr/local/lib/python2.7/dist-packages/taggit/managers.py:279: DeprecationWarning: `_TaggableManager.get_prefetch_query_set` method should be renamed `get_prefetch_queryset`.
  class _TaggableManager(models.Manager):
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/hp/django-trunk/django/core/management/__init__.py", line 426, in execute_from_command_line
    utility.execute()
  File "/home/hp/django-trunk/django/core/management/__init__.py", line 418, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/hp/django-trunk/django/core/management/base.py", line 244, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/hp/django-trunk/django/core/management/base.py", line 291, in execute
    output = self.handle(*args, **options)
  File "/home/hp/django-trunk/django/core/management/commands/makemigrations.py", line 75, in handle
    ProjectState.from_apps(apps),
  File "/home/hp/django-trunk/django/db/migrations/state.py", line 61, in from_apps
    model_state = ModelState.from_model(model)
  File "/home/hp/django-trunk/django/db/migrations/state.py", line 134, in from_model
    e,
TypeError: Couldn't reconstruct m2m field tags on BlogEntry: __init__() got an unexpected keyword argument 'serialize'

0 个答案:

没有答案