由于我们的应用程序有很多模型,我们将它们放在模型包的子包中,即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."
有谁知道如何解决这个问题?
答案 0 :(得分:1)
事实证明,问题在于Cheddar
实例的DataMigration
属性中未列出models
模型:
class Migration(DataMigration):
# ...
models = {
# ...
}
一旦我在那里添加了正确的模型定义(在我之前的迁移中),数据迁移就起作用了。