Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialshoval yechiel
4,465 PointsDateTimeField returns None
I am using python 3. when I make an object, i always get None. the exact code is
class Course(models.Model):
created_at = models.DateTimeField(auto_add_now=True)
title = models.CharField(max_length=255)
description = models.TextField()
I found on SOV the I can pass default=datetime.datetime.now()
but then I get an naive date error since its not compatible with timezones.
any suggestion ? also the 0001_initial.py made by python is
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_add_now=True)),
('title', models.CharField(max_length=255)),
('description', models.TextField()),
],
),
]
[MOD: added ```python formatting -cf]
1 Answer
Daniel Phillips
12,632 PointsTry changing auto_add_now
to auto_now_add