DateField(blank=True), null?

735 views
Skip to first unread message

Rares Vernica

unread,
Aug 14, 2006, 2:19:54 AM8/14/06
to django...@googlegroups.com
Hi,

I have a DateField with blank=True and after I complete and submit the
form I get a Django error saying that DateField cannot be null?

How can I set the DateField so that it can be empty, and eventually null
in the DB?

I don't like the idea of manually going and changing the DB schema.

Thanks,
Ray

James Bennett

unread,
Aug 14, 2006, 2:28:19 AM8/14/06
to django...@googlegroups.com
On 8/14/06, Rares Vernica <rver...@gmail.com> wrote:
> I have a DateField with blank=True and after I complete and submit the
> form I get a Django error saying that DateField cannot be null?

As the model documentation points out, you must also set 'null=True'
on the field to have the database accept NULL values; 'blank' is for
admin validation only, and has no effect on whether the database will
accept NULL.

The distinction is necessary to allow situations where a field can be
left blank via initial user input, but still requires that something
else fill it in before saving (for example, you might want to have a
field the user can fill in, but which will be filled with a default or
automatically-calculated value when left blank).

> I don't like the idea of manually going and changing the DB schema.

The column in the database will have been created with a NOT NULL
constraint; that constraint can only be removed by executing the
appropriate SQL statement for the database you're using.

--
"May the forces of evil become confused on the way to your house."
-- George Carlin

Bryan Chow

unread,
Aug 14, 2006, 2:39:53 AM8/14/06
to django...@googlegroups.com
Hi Ray,

You can set null=True on your DateField to allow null values in the
database. Foe example:

thedate = models.DateField(null=True, blank=True)

Cheers,
Bryan

Sidh Tanna

unread,
Jun 25, 2015, 6:41:56 PM6/25/15
to django...@googlegroups.com
Its not work dear, ou have any other solution?

Mario Gudelj

unread,
Jun 25, 2015, 7:25:59 PM6/25/15
to django...@googlegroups.com

Did you migrate? You don't have to manually edit your schema. Use migrations or south if you're using 1.6 or below.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/639bee6b-be77-403d-ad12-5bb9bb00f259%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Siddharth Tanna

unread,
Jun 25, 2015, 7:27:14 PM6/25/15
to django...@googlegroups.com
yes,its done

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/5zQiCO2C_AM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages