Hi everyone,
I'm having a problem with the "auto_now_add" option for DateField.

I was under the impression that when you set this option, a datestamp
is set automatically for you. But when I try inserting records into my
database without supplying a date for this field, I get a NULL value
error:

"calendar.date_added_to_db may not be NULL"

Below is the relevant portion of my model definition:

class Event(models.Model):
    date = models.DateField()
    title = models.TextField()
    url = models.URLField()
    date_added_to_db = models.DateField(auto_now_add=True)

And the results of python manage.py sqlall:

BEGIN;
CREATE TABLE "calendar" (
    "id" integer NOT NULL PRIMARY KEY,
    "date" date NOT NULL,
    "title" text NOT NULL,
    "url" varchar(200) NOT NULL,
    "date_added_to_db" date NOT NULL
)
;
COMMIT;

I'm confused as to why Django's ORM would translate the
"date_added_to_db" field as the above SQL. It would seem more
appropriate for the "date_added_to_db" field to be translated as the
following SQL:

     "DATETIME NOT NULL DEFAULT CURRENT_DATE"

With the above field definition, the datestamp is set automatically
for me when a record is created (which is the behavior I'm after).

Am I misconfiguring something, or is this an issue perhaps with the
implementation of the auto_now_add option for sqlite3? Or perhaps it's
convention to pass in the date/timestamp (though in that case, I don't
see the point of having the "auto_now_add" option....)?

 If it helps, I'm using sqlite3, Django 1.1 and Python 2.6.2.

Any advice is appreciated.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to