2013-05-14 78 views
0

我正在使用一個Django Web應用程序和南遷數據庫。我對南方頗爲陌生,而且django也是如此。我嘗試使用官方教程南部,但它失敗,例外:AttributeError:'選項'對象沒有屬性'index_together'。 我跑南方命令是這樣的:Django South schemamigration錯誤AttributeError:'選項'對象沒有屬性'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' 

謝謝

+1

你可以發佈你的模型? – 2013-05-14 17:12:23

+0

當然,我怎麼能發送代碼在這裏?或者我可以將示例項目發佈給您。 – user806135 2013-05-18 12:57:51

回答

1

它看起來像這是因爲你試圖在模型的元部分使用index_together選項。但是這個選項只適用於django 1.5+,我想你可以在不太新的版本的django上運行它。

+0

正如你在我的文章中看到的,我只是在meta部分設置了db_table,沒有其他的參數被觸動。 – user806135 2013-05-15 01:04:28

+0

你沒有南方的項目發射嗎?它仍然看着你錯過了一些東西。南沒有使用index_together屬性,除非你在你的模型中指定它 – Aldarund 2013-05-15 07:34:24

+0

我只是運行_manager.py runserver_命令多次,如果你的意思是這種'啓動'。我沒有觸及index_together,我的django版本是1.4 – user806135 2013-05-15 08:47:28

1

我更新了我的django到1.5.1,並且這個錯誤消失了。我不知道'index_together'是怎麼出來的,但是因爲它在django 1.5.1中可用,所以它得到了它所需要的。

6

這是南0.8的bug。只需更新到0.8.1或更新,一切都很好。

+1

我希望我可以不止一次地upvote :) – JivanAmara 2013-05-27 04:29:47

相關問題