Opened 9 years ago

Last modified 7 years ago

#25002 closed Bug

Postgresql migration fails when changing a CharField to a TimeField — at Version 2

Reported by: Dirk Uys Owned by: nobody
Component: Migrations Version: dev
Severity: Normal Keywords: migrations
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Dirk Uys)

The code from the migration is as follows:

migrations.AlterField(
    model_name='studygroup',
    name='time',
    field=models.TimeField(),
),

The field used to be a models.CharField()

The error follows:

django.db.utils.ProgrammingError: column "time" cannot be cast automatically to type time without time zone
HINT:  Specify a USING expression to perform the conversion

I can manually fix this using SQL:

ALTER TABLE "studygroups_studygroup" ALTER COLUMN "time" TYPE time USING "time"::time;

I don't have code with the problem isolated, but this project shows the problem when configured to use postgres. http://github.com/p2pu/knight-app/.

Change History (2)

comment:1 by Dirk Uys, 9 years ago

Component: UncategorizedDatabase layer (models, ORM)
Keywords: migrations added
Type: UncategorizedBug

comment:2 by Dirk Uys, 9 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top