0

Django's documentation mentions that all data should be converted to UTC when switching to USE_TZ=True. See: https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#other-databases

This is a rather concise remark. Are there any scripts/tricks available to do this in "one go", and to be able to easily do the same conversion in development and production.

I'd imagine this is not something one should do in South, since the USE_TZ setting is done at the project level whereas South migrations are bound to apps. Also, I'm not sure what view South would get from the data. Presumably South is reusing Django's ORM, so trying to do anything through that layer would lead to confusing results, and would also depend on whether the setting USE_TZ has already been changed to True. In fact, this could be said for any manipulation of the DB that routes through the ORM. Correct?

Many thanks,

Klaas

Klaas van Schelven
  • 2,374
  • 1
  • 21
  • 35

1 Answers1

1

When the docs say "data", it's talking about fixtures. Simply, you need to update any datetime strings in your fixtures when moving to a database that is TZ aware. So, the section futher down referring to fixtures contains the additional info you're looking for.

That said, this is not something that you should be changing back and forth between development and production. A lot of people like to use SQLite for development (for good reason), but it's unfortunately not currently TZ aware. So, if you need to create a site that is, you really need to use a different database in development. TZ aware data is tricky and this is not something you should be testing for the first time once you go to production. You should be dealing with it as you develop, so you know it will work in production.

As a result, Django's advice is focused on one-time migration of old TZ naive data to TZ aware data, not how you can switch them back and forth on a whim.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • I seriously doubt that the docs say "data" and talk about fixtures. The linked section specifically mentions the database type (and since fixtures don't live in the database I don't see how that would make any sense) Also, my question is what the best way to make the switch would be and your answer doesn't (yet) answer that. – Klaas van Schelven Jun 13 '12 at 16:21
  • The "best way", as the docs (under the "Fixtures" section) and I indicated, is to run `dumpdata` and then `loaddata`, and change any existing fixtures manually. Simply there's not really a good way to switch, you're going to have to do some work. Period. – Chris Pratt Jun 13 '12 at 17:00