OverflowError:应用迁移时mktime参数超出范围

时间:2013-10-16 20:20:11

标签: python django django-south

应用迁移时出现以下错误

RuntimeWarning: DateTimeField received a naive datetime (1970-01-01 00:00:00) while time zone support is active

Error in migration: webapp:0002_auto__add_field_quote_added_on
OverflowError: mktime argument out of range

应用此迁移时发生错误

import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

    def forwards(self, orm):
        # Adding field 'Quote.added_on'
        db.add_column('webapp_quote', 'added_on',
                      self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, default=datetime.datetime(1970, 1, 1, 0, 0), blank=True),
                      keep_default=False)


    def backwards(self, orm):
        # Deleting field 'Quote.added_on'
        db.delete_column('webapp_quote', 'added_on')


    models = {
        'webapp.quote': {
            'Meta': {'object_name': 'Quote'},
            'added_on': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'quote_source': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
            'quote_text': ('django.db.models.fields.TextField', [], {})
        }
    }

    complete_apps = ['webapp']

到这个模型

from django.db import models
from django.contrib.auth.models import User


class Quote(models.Model):
    quote_text = models.TextField()
    quote_source = models.CharField(max_length=100)
    added_on = models.DateTimeField(auto_now_add=True)
    added_by = models.ForeignKey(User, default=1)

1 个答案:

答案 0 :(得分:0)

安装pytz解决了这个问题。

South期待着一个时区感知DateTime,它只是一个天真的,因为没有安装pytz。