Skip to content

Instantly share code, notes, and snippets.

@julianwachholz
Last active August 29, 2015 14:17
Show Gist options
  • Save julianwachholz/96634b32ff823ee5e75e to your computer and use it in GitHub Desktop.
Save julianwachholz/96634b32ff823ee5e75e to your computer and use it in GitHub Desktop.
Django migration from `time without time zone` to `timestamp with time zone`
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('offers', '0001_initial'),
]
operations = [
migrations.RunSQL(
sql="""
ALTER TABLE offers_offer
ALTER COLUMN time TYPE timestamp with time zone
USING to_timestamp('2014-04-01 ' || time, 'YYYY-MM-DD HH24:MI:SS');
""",
reverse_sql="""
ALTER TABLE offers_offer
ALTER COLUMN time TYPE time without time zone;
""",
state_operations=[migrations.AlterField(
model_name='offer',
name='time',
field=models.DateTimeField(verbose_name='Offer time'),
preserve_default=True
)]
),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment