Ticket #684 (closed defect: wontfix)

Opened 5 years ago

Last modified 4 years ago

DateTimeField to DateField migration fails

Reported by: omar@… Owned by: andrew
Priority: major Milestone:
Component: migrations Version: 0.7.2
Keywords: Cc:


When i change a field from DateTimeField? to DateField?, django gives me:
invalid literal for int() with base 10: '02 15:54:53'
Db is Sqlite


0005_auto__chg_field_persona_nascita.py (1.4 KB) - added by omar@… 5 years ago.
migration file

Change History

Changed 5 years ago by omar@…

migration file

comment:1 Changed 5 years ago by me@…

Same problem here.

comment:2 Changed 4 years ago by mjumbewu@…

I just ran into this as well. I don't know whether other databases handle it well, but with sqlite, since dates and datetimes are just stored as strings, I had to add a line like this to the forward migration:

db.execute('UPDATE pro_persona SET nascita=date(nascita)')

and this to the backward migration:

db.execute('UPDATE pro_persona SET nascita=datetime(nascita)')

Should South just pick up on this? It seems SQLite-specific. Maybe when altering the column it should transform the data as well.

comment:3 Changed 4 years ago by andrew

  • Status changed from new to closed
  • Resolution set to wontfix

It's very SQLite-specific, and database-specific casts are something we haven't breached yet, and in this case something we literally cannot do - the column type is "int", so South has no way of knowing that the column was supposedly a datetime before (the alter_column calls are stateless).

Thus, I'm closing this WONTFIX, due to the fact I don't think it's possible to fix. There's another ticket open for having a nice way of specifying a custom casting operation in the Python that South generates, which would probably end up being the recommended solution to this.

Note: See TracTickets for help on using tickets.