尝试使用south迁移django应用程序时出错

时间:2009-05-19 04:36:40

标签: python database django migration

运行“./manage.py migrate 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的probs

问题 - 如何解决?

谢谢!

1 个答案:

答案 0 :(得分:2)

问题似乎与0001_initial.py文件中的模型顺序有关。有一个派生自AppUser的课程。当我使用

在Mac OS上重新创建迁移时
manage.py startmigration app --initial

并将其与Ubuntu上生成的模型进行比较,模型的顺序不同。因此,当我更改顺序以匹配Mac OS上的顺序时,一切正常。

这个问题似乎只存在于南方的0.5版本中,并且应该固定在主干上。