Contenttypes.contenttype is not available in this migration

I am trying to transfer several models from one Django application to another and based on this question How do I transfer a model from one django application to a new one? Ive got this pretty much worked, but when creating the first migration Im getting this error:

"The model 'contenttype' from the app 'contenttypes' is not available in this migration." 

Google and SO did not seem to find any cases for this, and the above question has nothing concrete to say about this other than a comment in the code:

 if not db.dry_run: # For permissions to work properly after migrating orm['contenttypes.contenttype'].objects.filter(app_label='common', model='cat').update(app_label='specific') 

It would be very helpful to understand what I am doing wrong.

Here are two migration files:

Create:

 # encoding: utf-8 import datetime from south.db import db from south.v2 import SchemaMigration from django.db import models class Migration(SchemaMigration): def forwards(self, orm): db.rename_table('cars_country', 'general_country') if not db.dry_run: # For permissions to work properly after migrating orm['contenttypes.ContentType'].objects.filter(app_label='cars', model='country').update(app_label='general') def backwards(self, orm): pass 

Delete

 # encoding: utf-8 import datetime from south.db import db from south.v2 import SchemaMigration from django.db import models class Migration(SchemaMigration): depends_on = ( ('general', '0002_create_country'), ) def forwards(self, orm): db.alter_column('cars_club', 'country_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['general.Country'], null=True)) def backwards(self, orm): db.rename_table('general_country', 'cars_country') db.alter_column('cars_club', 'country_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cars.Country'], null=True)) 
+6
source share
1 answer

Ok, found a solution. The dgel freeze notification made me check the South documentation as well as the ORM migration notification: this is achieved by serializing the models into a large dictionary called the model at the bottom of each migration. It is easy to see; its a big piece of dense code below.

So basically I just needed to move orm ['contenttypes.contenttype] to the second migration file, since the dictionary of content type models was already there. And now everything works as it should.

+4
source

All Articles