0

我正在开发一个带有南方的 Django Web 应用程序以进行数据库迁移。我对南方很陌生,django 也是如此。我尝试在官方教程中使用 south,但是失败并出现异常:AttributeError: 'Options' object has no attribute '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'  

谢谢

4

3 回答 3

6

这是南方0.8的错误。只需更新到 0.8.1 或更高版本,一切都会好起来的。

于 2013-05-25T07:51:51.183 回答
1

我将我的 django 更新到 1.5.1,这个错误消失了。我不知道“index_together”是如何产生的,但由于它在 django 1.5.1 中可用,它得到了它需要的东西。

于 2013-05-20T17:19:39.940 回答
1

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

于 2013-05-14T23:14:27.800 回答