Hi Robert,
On 17 sept. 2014, at 01:54, Robert Rollins <
coredu...@gmail.com> wrote:
> I have a legacy database from which my Django application must migrate data into a Django database. The relevant dates fields are actually TIMESTAMP columns in the database, but something (perhaps Django, or python's MySQL driver?) loads these columns as timezone naive datetime objects, rather than integers. So I wrote my migration code under the assumption that the dates coming out of the legacy database are timezone naive.
Unfortunately, you’re running into a known and documented limitation of time zone support in Django:
https://docs.djangoproject.com/en/dev/ref/databases/#timestamp-columns
> It seems like having USE_TZ = True is forcibly making my fixture dates timezone aware, which I don't want. But USE_TZ will be True during the actual migration, so I can't just turn it off during the tests. So how can I load timezone naive dates into my test database?
Would it be possible to:
- use USE_TZ = False during the migration process,
- convert datetimes to the proper timezone while migrating,
- then switch back to USE_TZ = True?
Based on my understanding of your situation, I believe this is the easiest path if you want to use the ORM.
Alternatives include:
- pull data with raw SQL queries — cursor.execute(…) — and insert it into the main database through Django,
- export data to a CSV file and re-import that.
I hope this helps,
--
Aymeric.