Ticket #684 (closed defect: wontfix)
DateTimeField to DateField migration fails
| Reported by: | omar@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | migrations | Version: | 0.7.2 |
| Keywords: | Cc: |
Description
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
Attachments
Change History
Changed 3 years ago by omar@…
- Attachment 0005_auto__chg_field_persona_nascita.py added
comment:2 Changed 21 months 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 21 months 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.

migration file