Southern instance data migration error when using southern orm freeze

I have a southern datamigration that is trying to create new objects based on data found in other models. When I try to create a new object for this "destination" model, I keep getting:

Cannot assign "<ContentType: ContentType object>": "Publishing.content_type" must be a "ContentType" instance. 

There seems to be something wrong with the "instance" when accessing through the southern ORM freeze, for example:

 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 

Now I have checked many times that content_type is actually an instance of ContentType, but somehow django does not count.

  • Is there any difference between the frozen, southern version of the instance instance and the native django?
  • What else could be possible?
+4
source share
1 answer

This is because the South models are processing. You must freeze any model you need to work with during the migration process. Models in the application in which the migration occurs are automatically frozen; all you have to freeze manually:

 python manage.py schemamigration --auto yourapp --freeze contenttypes 

If you have several applications that need to be frozen, repeat the --freeze argument --freeze many times as necessary:

 python manage.py schemamigration --auto yourapp --freeze contenttypes --freeze someotherapp ... 

One more thing. When you access these additional frozen models, you should use the old style Southern API API:

 orm['contenttypes.contenttype'].objects.all() 

Something like orm.ContentType does not work.

+8
source

All Articles