AlterField on auto generated _ptr field in migration causes FieldError
<p>I have two models:</p>

<pre><code># app1
class ParentModel(models.Model):
    # some fields
</code></pre>

<p>Now, in another app, I have child model:</p>

<pre><code># app2
from app1.models import ParentModel


class ChildModel(ParentModel):
    # some fields here too
</code></pre>

<p>In initial migration for <code>app2</code> django creates <code>OneToOneField</code> with <code>parent_link=True</code> named <code>parentmodel_ptr</code>.</p>

<p>Now I want to change this auto generated field to let's say <code>IntegerField</code>, so I create new migration with this operations:</p>

<pre><code>class Migration(migrations.Migration):

    dependencies = [
        ('app2', '0001_initial'),
    ]

    operations = [
        migrations.AlterField(
            'childmodel',
            'parentmodel_ptr',
            models.IntegerField(null=True, blank=True)
        )
    ]
</code></pre>

<p>Trying to migrate, I got an exception </p>

<pre><code>django.core.exceptions.FieldError: Auto-generated field 'parentmodel_ptr' in class 'ChildModel' for parent_link to base class 'ParentModel' clashes with declared field of the same name.
</code></pre>

<p>So is that even possible to make it somehow?</p>

<p>If your code supports it, you could just change the parent class to an abstract class and have all the fields in the child model. However, if you still do need the parent object separately, then I don't think you can change the Django OneToOne link without some serious hacking (not recommended).  </p>

<p>If you only need the relation and don't need the methods, etc. then you could remove the inheritance and go with a self-created either OneToOneField or an IntegerField that holds the ForeignKey to that other object. You could elaborate the question with your end goal, so it would be simpler to offer real solutions rather than theories.</p>

python django database-migration