尝试迁移django应用程序与南时出错 [英] Error when trying to migrate django application with south

查看:177
本文介绍了尝试迁移django应用程序与南时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行./manage.py migrate app_name时遇到此错误

I am getting this error when running "./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

I am sure that model "appuser" is both in application models.py and in 0001_initial.py

来自models.py的AppUser模型:

AppUser model from models.py:

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模型:

AppUser model from 0001_initial.py:

    # 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_ *表):

I am trying to run it on empty database (ie. no "app_*" tables) like that:

manage.py migrate app

这似乎只发生在Mac OS上的python 2.5,没有probs与Ubuntu / python 2.6

This seem to be happening only on python 2.5 on Mac OS, no probs with Ubuntu/python 2.6

问题 - 如何解决?

谢谢!

推荐答案

问题似乎是在0001_initial.py文件中的模型顺序。有一个派生自AppUser的类。当我在Mac OS上使用

The problem seemed to be with the order of models in the 0001_initial.py file. There was a class which derived from AppUser. When I re-created the migration on Mac OS with

manage.py startmigration app --initial

并将其与Ubuntu上生成的模型的顺序不同。所以当我改变顺序匹配一个在Mac OS上,一切工作正常。

and compared that to one generated on Ubuntu the order of models was different. So when I changed the order to match the one on Mac OS, everything worked fine.

这个问题似乎只存在于0.5版本的南部, 。

This problem seems to exist only in 0.5 version of south and is supposedly fixed on trunk.

这篇关于尝试迁移django应用程序与南时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆