2013-10-16 30 views
2

由于我们的应用有很多模型,我们将它们放在模型包的子包中,即Cheddar模型不会在models.Cheddar中,而是在models.cheese.CheddarDjango South:我如何访问迁移中的子包中的模型

看来我无法在南数据迁移中访问这些模型,即使我创建了models/__init__.py根据this answer包含行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

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

class Migration(DataMigration): 
    # ... 

    models = { 
     # ... 
    } 

一旦我加在里面了正确的模型定义(这是在以前的为我迁移),数据迁移工作。