【发布时间】:2011-06-02 06:03:05
【问题描述】:
我有一个南方数据迁移,它试图根据在其他模型中找到的数据创建新对象。当尝试为给定的“目标”模型创建一个新对象时,我不断得到:
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 不这么认为。
- 实例的“冻结”South orm 版本与原生 django 版本之间有区别吗?
- 这还可能是什么?
【问题讨论】:
-
达里尔,我面临同样的问题 goo.gl/I7Jj6 你设法解决了吗?我现在正在尝试使用 content_type 和 object_id 在数据迁移中创建一个新实例,但得到您在上面发布的确切错误。
标签: django data-migration django-south