'Test that defaults are correctly not created for datetime columns'

@skipUnless(db.raises_default_errors, 'This    database    does    not    raise    errors    on    missing    defaults.')
def test_datetime_default(self):

    end_of_world = datetime.datetime(2012, 12, 21, 0, 0, 1)
    try:
        from django.utils import timezone
    except ImportError:
        pass
    else:
        from django.conf import settings
        if getattr(settings, 'USE_TZ', False):
            end_of_world = end_of_world.replace(tzinfo=timezone.utc)
    db.create_table('test_datetime_def', [('col0', models.IntegerField(null=True)), ('col1', models.DateTimeField(default=end_of_world)), ('col2', models.DateTimeField(null=True))])
    db.execute_deferred_sql()
    db.execute('INSERT    INTO    test_datetime_def    (col0,    col1,    col2)    values    (null,%s,null)', [end_of_world])
    db.alter_column('test_datetime_def', 'col2', models.DateTimeField(default=end_of_world))
    db.add_column('test_datetime_def', 'col3', models.DateTimeField(default=end_of_world))
    db.execute_deferred_sql()
    db.commit_transaction()
    db.start_transaction()
    ends = db.execute('select    col1,col2,col3    from    test_datetime_def')[0]
    self.failUnlessEqual(len(ends), 3)
    for e in ends:
        self.failUnlessEqual(e, end_of_world)
    db.commit_transaction()
    for cols in ['col1,col2', 'col2,col3']:
        db.start_transaction()
        statement = ('insert    into    test_datetime_def    (col0,%s)    values    (null,%%s,%%s)' % cols)
        self.assertRaises(IntegrityError, db.execute, statement, [end_of_world, end_of_world])
        db.rollback_transaction()
    db.start_transaction()
