Django South:如何在迁移中访问子包中的模型

时间:2013-10-16 09:48:18

标签: python django django-south data-migration

由于我们的应用程序有很多模型,我们将它们放在模型包的子包中,即Cheddar模型不在models.Cheddar中,而是放在models.cheese.Cheddar中。< / p>

我似乎无法在南方数据迁移中访问这些模型,即使我根据this answer创建了一个models/__init__.py,其中包含第from cheese import *行。

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

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

尝试使用orm['core.models.cheese.Cheddar']代替此错误:

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

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

1 个答案:

答案 0 :(得分:1)

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

class Migration(DataMigration):
    # ...

    models = {
        # ...
    }

一旦我在那里添加了正确的模型定义(在我之前的迁移中),数据迁移就起作用了。