Opened 8 years ago

Closed 5 years ago

#27338 closed Cleanup/optimization (fixed)

Running an AlterField to change a CharField primary key to AutoField crashes.

Reported by: Tim Graham Owned by: nobody
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mads Jensen)

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.

Change History (5)

comment:1 by Tim Graham, 8 years ago

#27339 is related.

comment:2 by Mads Jensen, 8 years ago

Description: modified (diff)

comment:3 by Nathan Self, 7 years ago

PostgreSQL gives the same error if you use AlterField to change a CharField to a ForeignKey.

Last edited 7 years ago by Nathan Self (previous) (diff)

comment:4 by GitHub <noreply@…>, 5 years ago

In c8250ef:

Refs #27338 -- Added tests for altering CharField with primary_key=True to AutoField on PostgreSQL.

Fixed in 91b2bc3e70be2632baad86488fb03cf02848b5b6.

comment:5 by Mariusz Felisiak, 5 years ago

Resolution: fixed
Status: newclosed
Summary: Running an AlterField to change a CharField primary key to AutoField crashesRunning an AlterField to change a CharField primary key to AutoField crashes.
Note: See TracTickets for help on using tickets.
Back to Top