Django error: datetime.datetime
Question: When I execute `python manage.py migrate`, I get this error on the screen:

    
    
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 146, in column
    sql
    default_value = self.effective_default(field)
    
    File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/schema.py", line 211, in effect
    ive_default
    default = field.get_db_prep_save(default, self.connection)
    
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init_.py", line 710, in get_
    db_prep_save
    prepared=False)
    
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/init.py", line 2003, in get
    db_prep_value
    value = self.get_prep_value(value)
    
    File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init_.py", line 2010, in get
    _prep_value
    if value and ':' in value:
    TypeError: argument of type 'datetime.datetime' is not iterable
    

I tried to execute `python manage.py syncdb` but the same error appears. What
could be the issue?

`Models.py` for more information:

    
    
      from django.db import models
      import datetime
      from django.utils import timezone
    
     class Machine(models.Model):
       name = models.CharField(max_length=20, unique=True)
       ins_date = models.DateField(default=timezone.now)
       mod_date = models.DateField(default=timezone.now)
       nagios_name = models.CharField(max_length=20)
       dns = models.CharField(max_length=30)
       ip_int = models.GenericIPAddressField(null=True, blank=True)
       ip_ext = models.GenericIPAddressField()
       vlan = models.IntegerField(null=True, blank=True)
       custom = models.BooleanField(default=False)
       def __str__(self):
         return self.name
    
     class SecurityGroup(models.Model):
       name = models.CharField(max_length=20)
       description = models.CharField(max_length=30, null=True, blank=True)
       ins_date = models.DateField(default=timezone.now)
       mod_date = models.DateField(default=timezone.now)
       def __str__(self):
         return self.name
    
     class NACL(models.Model):
       machine = models.ForeignKey(Machine)
       securityGroup = models.ForeignKey(SecurityGroup)
       ins_date = models.DateField(default=timezone.now)
       mod_date = models.DateField(default=timezone.now)
    
     BYADMIN_CHOICES = ((1, "Input"),(0, "Output"),)
    
     class Rule(models.Model):
       type_rule = models.CharField(max_length=10)
       description = models.CharField(max_length=30, null=True, blank=True,   default=None)
       protocol = models.CharField(max_length=10)
       port_range_min = models.IntegerField()
       port_range_max = models.IntegerField(null=True, blank=True)
       #sg_object = models.CharField(max_length=20, null=True, blank=True)
       ip_object = models.GenericIPAddressField(null=True, blank=True)
       securityGroup_object = models.ForeignKey(SecurityGroup, null=True, blank=True)
       bound = models.BooleanField(choices=BYADMIN_CHOICES, default=1) #if           bound == True: input else: output 
      class Meta:
        unique_together = (("type_rule", "protocol", "port_range_min", "bound"))
      def __str__(self):
        return ("INPUT: " if(self.bound) else "OUTPUT: ") + self.type_rule + " " + self.protocol + " " + str(self.port_range_min) + " " + (str(self.securityGroup_object) if(self.securityGroup_object != None) else self.ip_object)
    
     class Sg_rule(models.Model):
       securityGroup = models.ForeignKey(SecurityGroup)
       rule = models.ForeignKey(Rule)
       ins_date = models.DateField(default=timezone.now)
       mod_date = models.DateField(default=timezone.now)
    
     class Service(models.Model):
       name = models.CharField(max_length=20)
       macroService = models.CharField(max_length=20)
       def __str__(self):
         return self.name
    
    
     class M_Service(models.Model):
       machine = models.ForeignKey(Machine)
       service = models.ForeignKey(Service)
       ins_date = models.DateField(default=timezone.now)
       mod_date = models.DateField(default=timezone.now)
    

And the migration that is failing:

    
    
    # -*- coding: utf-8 -*-
    from __future__ import unicode_literals
    
    from django.db import migrations, models
    import datetime
    from django.utils.timezone import utc
    
    
    class Migration(migrations.Migration):
    
    dependencies = [
        ('adminApp', '0009_auto_20160229_1716'),
    ]
    
    operations = [
        migrations.AddField(
            model_name='rule',
            name='ip_object',
            field=models.GenericIPAddressField(default=datetime.datetime(2016, 2, 29, 17, 17, 42, 169176, tzinfo=utc)),
            preserve_default=False,
        ),
        migrations.AlterField(
            model_name='rule',
            name='sg_object',
            field=models.CharField(max_length=20),
        ),
    ]
    


Answer: Your migration is trying to use a datetime as the default for an ip address
field. That doesn't make sense!

    
    
    field=models.GenericIPAddressField(default=datetime.datetime(2016, 2, 29, 17, 17, 42, 169176, tzinfo=utc)),
    

