0

我写了一个用 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'
4

0 回答 0