Ticket #781 (assigned defect)
Model Instances not valid when used as arguments for creating another object
| Reported by: | daryl@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | 1.0 |
| Component: | migrations | Version: | 0.7.3 |
| Keywords: | Cc: |
Description
I'm having trouble with creating new objects in a datamigration.
When using object instances from the South orm, e.g. content_type_instance = ormcontenttypes.ContentType?.objects.get(ct_kwargs)
to create another object:
publishing_kwargs = {
'site': site if isinstance(site, Site) else Site.objects.get(id=site.id),
'publishing_type': publishing_type_instance,
'start': start,
'content_type': content_type_instance,
'object_id': content_object.id, }
publishing = orm.Publishing(publishing_kwargs)
I get a ValueError?:
Cannot assign "<ContentType: ContentType object>": "Publishing.content_type" must be a "ContentType?" instance.
See also:
Attachments
Change History
Changed 2 years ago by daryl@…
- Attachment 0006_convert_remaining_content_objects.py added
comment:1 Changed 2 years ago by andrew
- Status changed from new to assigned
- Milestone set to 1.0
This is because the south ORM classes of models are _not the same_ as the main Django classes for your models - they won't compare equal, and you can't feed instances of one type into a ForeignKey? of another type.
Unfortunately, knowing which kind a ForeignKey? is can sometimes be tricky. Have you tried both with and without the orm version of ContentType??
Changed 2 years ago by daryl@…
- Attachment 0006_convert_remaining_content_objects.2.py added
updated data migration with hopeful fixes
comment:2 Changed 2 years ago by daryl@…
Thanks @andrew, I've reattached an updated version of the file whereas I attempt to get the 'native' instances for use in creating new objects.
With the 'Publishing' object that I'm trying to create, you'll notice at the bottom that I try the 3 possible notations for creating objects, two of them via the south orm, and the third via native django.
Each of them returns the instance error, however, curiously, complaining about different objects, i.e. sometimes about the content_type, and sometimes about the 'site'.
I've included the output from the print statements found in the migration.
I had a 'feeling' that orm.ContentType? != ContentType? -- yet, this issue seems to be baffling.

datamigration file