簡體   English   中英

嘗試向南遷移Django應用程序時出錯

[英]Error when trying to migrate django application with south

運行“ ./manage.py migration app_name”時出現此錯誤

While loading migration 'whatever.0001_initial':
Traceback (most recent call last):
 File "manage.py", line 14, in <module> execute_manager(settings)

...tons of other stuff..

   raise KeyError("The model '%s' from the app '%s' is not available in this migration." % (model, app))
KeyError: "The model 'appuser' from the app 'whatever' is not available in this migration."

我確定模型“ appuser”在應用程序models.py和0001_initial.py中都存在

來自models.py的AppUser模型:

class AppUser(models.Model):
    person = models.OneToOneField('Person')
    user = models.ForeignKey(User, unique=True)
    class Meta:
        permissions = (
            ('is_one', 'one'),
            ('is_two', 'two')
        )
    def __unicode__(self):
        return self.person.__unicode__()

0001_initial.py中的AppUser模型:

    # Adding model 'AppUser'
    db.create_table('app_appuser', (
        ('person', models.OneToOneField(orm.Person)),
        ('id', models.AutoField(primary_key=True)),
        ('user', models.ForeignKey(orm['auth.User'], unique=True)),
    ))
    db.send_create_signal('app', ['AppUser'])
    ...
    'app.appuser': {
        'Meta': {'permissions': "(('is_one','one'),('is_two','two'))"},
        'id': ('models.AutoField', [], {'primary_key': 'True'}),
        'person': ('models.OneToOneField', ["'Person'"], {}),
        'user': ('models.ForeignKey', ['User'], {'unique': 'True'})
    },

我試圖像這樣在空數據庫(即沒有“ app_ *”表)上運行它:

manage.py migrate app

這似乎僅在Mac OS上的python 2.5上發生,而Ubuntu / python 2.6則沒有問題

問題-如何解決?

謝謝!

問題似乎與0001_initial.py文件中的模型順序有關。 從AppUser派生了一個類。 當我使用以下命令在Mac OS上重新創建遷移時

manage.py startmigration app --initial

與在Ubuntu上生成的模型相比,模型的順序有所不同。 因此,當我更改訂單以與Mac OS上的訂單匹配時,一切正常。

這個問題似乎僅在南方的0.5版本中存在,並且據說已經在樹干上解決了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM