--
Ticket URL: <https://code.djangoproject.com/ticket/27338>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Tim Graham):
#27339 is related.
--
Ticket URL: <https://code.djangoproject.com/ticket/27338#comment:1>
Old description:
> For example: change `id = models.CharField(max_length=20,
> primary_key=True)` to `id = models.AutoField(primary_key=True)`. It
> generates this operation:
> {{{
> migrations.AlterField(
> model_name='foo',
> name='id',
> field=models.AutoField(primary_key=True, serialize=False),
> ),
> }}}
> Running it on PostgreSQ gives: `django.db.utils.ProgrammingError:
> operator class "varchar_pattern_ops" does not accept data type integer`.
> I'm not sure if this can be made to work sensibly. Is it possible to
> autopopulate the `AutoField`? I ran into this situation while
> investigating #27267.
New description:
For example: change `id = models.CharField(max_length=20,
primary_key=True)` to `id = models.AutoField(primary_key=True)`. It
generates this operation:
{{{
migrations.AlterField(
model_name='foo',
name='id',
field=models.AutoField(primary_key=True, serialize=False),
),
}}}
Running it on PostgreSQL gives: `django.db.utils.ProgrammingError:
operator class "varchar_pattern_ops" does not accept data type integer`.
I'm not sure if this can be made to work sensibly. Is it possible to
autopopulate the `AutoField`? I ran into this situation while
investigating #27267.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/27338#comment:2>
Comment (by Nathan Self):
PostgreSQL gives the same error if you use AlterField to change a
CharField primary key to a ForeignKey.
--
Ticket URL: <https://code.djangoproject.com/ticket/27338#comment:3>
Comment (by GitHub <noreply@…>):
In [changeset:"c8250ef361dcb4c7ed76632e4308c6db22da77d0" c8250ef]:
{{{
#!CommitTicketReference repository=""
revision="c8250ef361dcb4c7ed76632e4308c6db22da77d0"
Refs #27338 -- Added tests for altering CharField with primary_key=True to
AutoField on PostgreSQL.
Fixed in 91b2bc3e70be2632baad86488fb03cf02848b5b6.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27338#comment:4>
* status: new => closed
* resolution: => fixed
Comment:
Fixed in 91b2bc3e70be2632baad86488fb03cf02848b5b6.
--
Ticket URL: <https://code.djangoproject.com/ticket/27338#comment:5>