Why GenericRelation fields does not work in Data Migrations(Django)
<p>I want to make data migration in order to add user read post in database. There is such code:</p>

<pre><code>def user_read_posts(apps, schema_editor):
    User = apps.get_model("main", "User")
    Post = apps.get_model("main", "Post")
    Comment = apps.get_model("comments", "Comment")

    comments = Comment.objects.all()
    for comment in comments:
        print (comment.content_object.__class__.__name__)
        if isinstance(comment.content_object, Post):
            comment.user.read_posts.add(comment.content_object)

class Migration(migrations.Migration):

    dependencies = [
        ('main', '0039_auto_20160314_0906'),
    ]

    operations = [
        migrations.RunPython(user_read_posts),
    ]
</code></pre>

<p>And in line  <code>print (comment.content_object.__class__.__name__)</code> django raise error:
<code>AttributeError: 'Comment' object has no attribute 'content_object'</code></p>

<p>Comment model:</p>

<pre><code>class GuidaComment(GenericRelationModel):

    user = models.ForeignKey(GuidaUser)
    text = models.TextField()
</code></pre>

<p>So what should I do?</p>

<p>Thanks.</p>