我有一个南方数据迁移,它试图根据其他模型中找到的数据创建新对象。当尝试为给定的“目标”模型创建新对象时,我不断收到:
Cannot assign "<ContentType: ContentType object>": "Publishing.content_type" must be a "ContentType" instance.
通过 South freeze ORM 访问时,“实例”似乎有问题,例如:
ContentType = orm['contenttypes.ContentType']
content_type_kwargs = {
'model': ContentModel._meta.module_name,
'app_label': ContentModel._meta.app_label, }
content_type = ContentType.objects.get(**content_type_kwargs)
# further down
publishing_kwargs = {
'site': Site.objects.get_current(),
'publishing_type': publishing_type,
'start': start,
'content_type': content_type,
'object_id': content_object.id, }
publishing = orm.Publishing(**publishing_kwargs) # Produces the error above
现在我已经多次验证了content_type
实际上是 ContentType 的一个实例——但不知何故 django 并不这么认为。
- 实例的“冻结”南 Orm 版本和本机 django 版本之间有区别吗?
- 这还可能是什么?
这是由于 South 处理模型的方式。你must冻结您在迁移中需要使用的任何模型。迁移所在的应用程序中的模型会自动冻结;其他必须手动冻结的内容:
python manage.py schemamigration --auto yourapp --freeze contenttypes
如果您有多个应用程序需要冻结,请重复--freeze
根据需要多次论证:
python manage.py schemamigration --auto yourapp --freeze contenttypes --freeze someotherapp ...
另一件事。当您访问这些额外的冻结模型时,您必须使用旧式 South API:
orm['contenttypes.contenttype'].objects.all()
就像是orm.ContentType
行不通的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)