[Django] #27338: Running an AlterField to change a CharField primary key to AutoField crashes

10 views
Skip to first unread message

Django

unread,
Oct 12, 2016, 8:47:42 PM10/12/16
to django-...@googlegroups.com
#27338: Running an AlterField to change a CharField primary key to AutoField
crashes
------------------------------------------------+------------------------
Reporter: Tim Graham | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/27338>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 12, 2016, 8:57:00 PM10/12/16
to django-...@googlegroups.com
#27338: Running an AlterField to change a CharField primary key to AutoField
crashes
--------------------------------------+------------------------------------

Reporter: Tim Graham | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Tim Graham):

#27339 is related.

--
Ticket URL: <https://code.djangoproject.com/ticket/27338#comment:1>

Django

unread,
Oct 31, 2016, 5:42:19 AM10/31/16
to django-...@googlegroups.com
#27338: Running an AlterField to change a CharField primary key to AutoField
crashes
--------------------------------------+------------------------------------

Reporter: Tim Graham | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Description changed by Mads Jensen:

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>

Django

unread,
Sep 13, 2017, 6:11:15 PM9/13/17
to django-...@googlegroups.com
#27338: Running an AlterField to change a CharField primary key to AutoField
crashes
--------------------------------------+------------------------------------

Reporter: Tim Graham | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Sep 11, 2019, 7:41:52 AM9/11/19
to django-...@googlegroups.com
#27338: Running an AlterField to change a CharField primary key to AutoField
crashes
--------------------------------------+------------------------------------

Reporter: Tim Graham | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Sep 11, 2019, 7:42:23 AM9/11/19
to django-...@googlegroups.com
#27338: Running an AlterField to change a CharField primary key to AutoField
crashes.
--------------------------------------+------------------------------------

Reporter: Tim Graham | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => fixed


Comment:

Fixed in 91b2bc3e70be2632baad86488fb03cf02848b5b6.

--
Ticket URL: <https://code.djangoproject.com/ticket/27338#comment:5>

Reply all
Reply to author
Forward
0 new messages