Hi, I'm migrating an app from Django 1.6 to 1.7 and I need to create a data migration to load some initial data.
Some of the migrations requires that Content Types are populated in order to create some objects with Generic Relations. # models.py class TincHost(models.Model): name = models.CharField(max_length=32, unique=True) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() class Server(models.Model): name = models.CharField(max_length=256, unique=True) tinc = generic.GenericRelation(TincHost) # migrations/0002_initial_data.py def create_tinc_server(apps, schema_editor): # ... TincHost.objects.create(content_type=ctype, object_id=1, name='server') class Migration(migrations.Migration): dependencies = [ ('contenttypes', '0001_initial'), ('myapp', '0001_initial'), ] operations = [ migrations.RunPython(create_tinc_server) ] This page[1] suggests adding this code to the migration: from django.contrib.contenttypes.management import update_all_contenttypes update_all_contenttypes() It works, but there is a better or standar way to achieve that? [1] http://stackoverflow.com/q/26464838/1538221 Thanks! -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5b2d48da-41b3-404d-abff-6c17c017aa10%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.