由于我们的应用程序有很多模型,因此我们将它们放置在 models 包的子包中,即Cheddar
模型不会在models.Cheddar
,而是在models.cheese.Cheddar
.
看来我无法在南方数据迁移中访问这些模型,即使我创建了一个models/__init__.py
as per 这个答案 https://stackoverflow.com/a/8123602/54547包含该行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."
有谁知道如何解决这个问题?
事实证明,问题在于,Cheddar
型号未在列表中列出DataMigration
实例的models
财产:
class Migration(DataMigration):
# ...
models = {
# ...
}
一旦我在其中添加了正确的模型定义(这是我之前的迁移中的),数据迁移就起作用了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)