Django South schemamigration错误AttributeError:'Options'对象没有属性'index_together'

时间:2013-05-14 17:07:32

标签: django django-models django-south

我正在使用南方的Django Web应用程序进行数据库迁移。我对南方很新,还有django。我尝试使用南方的官方教程,但是它失败了,例外: AttributeError:'Options'对象没有属性'index_together'。 我像这样运行南方命令:

python manage.py schemamigration southtut --initial  

southtut模型是:

class Knight(models.Model):
    name = models.CharField(max_length=100)
    of_the_round_table = models.BooleanField()

我的项目模型是:

class Author(models.Model):
    name = models.CharField(max_length=64)
    authorId = models.CharField(max_length=32)

    def __unicode__(self):
        return self.name

    class Meta:
        db_table="Author"   

class Video(models.Model):
    videoId = models.CharField(max_length=32)
    videoUrl = models.URLField(max_length=200)
    author = models.ForeignKey(Author, null=True, related_name="videos", on_delete=models.SET_NULL)

    class Meta:
        db_table="Video"

class User(models.Model):
    token = models.CharField(max_length=50, null=True)
    favs = models.ManyToManyField(Video, related_name="fans", db_table="VideoUserR")

    class Meta:
        db_table = "User"

我收到的整个错误信息如下:

    Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/Library/Python/2.7/site-packages/South-0.7.6-py2.7.egg/south/management/commands/schemamigration.py", line 151, in handle
    for action_name, params in change_source.get_changes():
  File "/Library/Python/2.7/site-packages/South-0.7.6-py2.7.egg/south/creator/changes.py", line 460, in get_changes
    model_defs = freeze_apps([self.migrations.app_label()])
  File "/Library/Python/2.7/site-packages/South-0.7.6-py2.7.egg/south/creator/freezer.py", line 37, in freeze_apps
    model_defs[model_key(model)] = prep_for_freeze(model)
  File "/Library/Python/2.7/site-packages/South-0.7.6-py2.7.egg/south/creator/freezer.py", line 78, in prep_for_freeze
    fields['Meta'] = remove_useless_meta(modelsinspector.get_model_meta(model))
  File "/Library/Python/2.7/site-packages/South-0.7.6-py2.7.egg/south/modelsinspector.py", line 441, in get_model_meta
    meta_def[kwd] = get_value(model._meta, defn)
  File "/Library/Python/2.7/site-packages/South-0.7.6-py2.7.egg/south/modelsinspector.py", line 258, in get_value
    value = get_attribute(field, attrname)
  File "/Library/Python/2.7/site-packages/South-0.7.6-py2.7.egg/south/utils/__init__.py", line 38, in get_attribute
    value = getattr(value, part)
AttributeError: 'Options' object has no attribute 'index_together'  

由于

3 个答案:

答案 0 :(得分:6)

这是南0.8的错误。只需更新到0.8.1或更新,一切都很好。

答案 1 :(得分:1)

看起来这是因为您尝试在模型的Meta部分中使用index_together选项。但是这个选项仅适用于django 1.5+,我猜你是在较新版本的django上运行它。

答案 2 :(得分:1)

我将django更新为1.5.1,此错误消失了。我不知道'index_together'是如何出现的,但由于它在django 1.5.1中可用,它可以得到它所需要的。