Django South:如何在迁移中访问子包中的模型 [英] Django South: How can I access models in sub-packages in migrations

查看:94
本文介绍了Django South:如何在迁移中访问子包中的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我们的应用程序有许多型号,我们将它们放在模型包的子包中,即 Cheddar 模型不会在模型中.Cheddar ,而是在 models.cheese.Cheddar 中。



似乎我即使我根据 models / __ init __。py ,无法在南方数据迁移中访问这些模型/ 54547>这个答案包含来自奶酪进口的



在我的数据迁移文件,orm.Cheddar.objects.all()中的cheddar行仍然导致以下错误:

  AttributeError:在此迁移中,核心应用程序中的Cheddar模型不可用。 (你使用orm.ModelName,不是orm ['app.ModelName']?)

试图使用 orm ['core.models.cheese.Cheddar'] 而不是导致此错误:

  KeyError:在这个迁移中,应用程序'core'中的模型'cheddar'不可用。 

有没有人知道如何解决这个问题?

解决方案

事实证明,问题在于, Cheddar 模型未列在 DataMigration 实例的模型属性:

  class Migration(DataMigration):
#...

models = {
#...
}

一旦我在其中添加了正确的模型定义(这在我之前的迁移中),数据迁移就可以工作。


Since our app has many models, we place them in sub-packages of the models packages, i.e. the Cheddarmodel would not be in models.Cheddar, but instead in models.cheese.Cheddar.

It seems I cannot access these models in a South datamigration, even though I created an models/__init__.py as per this answer containing the line from cheese import *.

In my data migration file, the line for cheddar in orm.Cheddar.objects.all(): still causes the following error:

AttributeError: The model 'Cheddar' from the app 'core' is not available in this migration. (Did you use orm.ModelName, not orm['app.ModelName']?)

Trying to use orm['core.models.cheese.Cheddar'] instead causes this error:

KeyError: "The model 'cheddar' from the app 'core' is not available in this migration."

Does anyone know how to work around this problem?

解决方案

Turns out, the problem was in the fact, that the Cheddar model was not listed in the DataMigration instance's modelsproperty:

class Migration(DataMigration):
    # ...

    models = {
        # ...
    }

Once I added the correct model definition in there (which was in the previous migration for me), the data migration worked.

这篇关于Django South:如何在迁移中访问子包中的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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