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

发布于 2024-07-21 03:20:19 字数 1717 浏览 4 评论 0原文

运行“./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 中,又在

models.py 中的 0001_initial.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 没有问题

问题 - 如何修复?

谢谢!

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."

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

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__()

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'})
    },

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

manage.py migrate app

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

Question - how to fix?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓬勃野心 2024-07-28 03:20:19

问题似乎与 0001_initial.py 文件中的模型顺序有关。 有一个从 AppUser 派生的类。 当我在 Mac OS 上重新创建迁移

manage.py startmigration app --initial

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

这个问题似乎只存在于south 0.5版本中,据说在trunk上已经修复了。

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

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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文