Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

contenttypes.contenttype not available in this migration

I’m trying to migrate a few models from one Django app to another and based on this question How do I migrate a model out of one django app and into a new one? I’ve got it pretty much worked but when creating the first migration I’m getting this error:

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

Google and SO doesn’t seem to find any cases for this happening and the aforementioned question doesn’t have anything specific to say about it either, except the 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')

Would really appreciate any insight into what am I doing wrong.

Here are the 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))
like image 310
margusholland Avatar asked Nov 28 '12 00:11

margusholland


Video Answer


1 Answers

Ok, found the solution. The freezing notice from dgel got me checking the South documentation and there’s a notice about the ORM migration: This is accomplished by serialising the models into a large dictionary called models at the bottom of every migration. It’s easy to see; it’s the large chunk of dense code at the bottom.

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

like image 195
margusholland Avatar answered Oct 17 '22 02:10

margusholland