When I try to add a new field or modify my model in any way I get the following error when I try to migrate to the database:
File "C:\Users\uddin\Envs\web\lib\site-packages\django\db\models\fields\__init__.py", line 1913, in get_prep_value if value and ':' in value: TypeError: argument of type 'datetime.datetime' is not iterable
This is what my model.py file looks like
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
from PIL import Image
class Post(models.Model):
title = models.CharField(max_length=100)
title2 = models.CharField( max_length=100)
content = models.TextField()
content2 = models.TextField(default=None)
post_image = models.ImageField(upload_to='post_pics')
post_image2 = models.ImageField(upload_to='post2_pics')
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('post-detail', kwargs={'pk': self.pk})
Full traceback of error
I've added the full traceback in a pastebin as not to make the post too long
front.0008_post_location file
# Generated by Django 3.1.5 on 2021-03-06 01:21
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('front', '0007_post_content'),
]
operations = [
migrations.AddField(
model_name='post',
name='location',
field=models.GenericIPAddressField(default=django.utils.timezone.now),
preserve_default=False,
),
]
Any help would be appreciated
GenericIPAddressFieldanywhere in your models?GenericIPAddressFieldin my models.front.0008_post_location