On Fri, Feb 26, 2010 at 5:35 PM, Wayne <wayneshen...@gmail.com> wrote:

> Hi,
> I try to create tables using Django models in our test oracle
> database. I define a model with one column like this: name =
> models.CharField(max_length=512, null=False, blank=False). After
> running python manage.py syncdb, I found that column 'name' in the
> generated table still allows null value in the column definition. I
> understand that null = false is the default option. And I verified
> that for other types of Django fields, null = false or no such option
> at all would generate columns that do not allow null values in the
> database. Is there particular reason why null = false is not enforced
> for charField?


Yes. Oracle does not distinguish between null and an empty string. So
null=False applied at the database level would mean that you also could not
store the empty string in that field, which would be quite different from
what you would see running the same code on most other databases, where the
empty string is a valid value for a NOT NULL character field.

The behavior is documented, see the note here:
http://docs.djangoproject.com/en/dev/ref/models/fields/#null. The note is
perhaps not as clear as it could be about when the empty string is allowed
for a field. That's a property of the field type (for example, empty strings
are allowed for CharField but not a DateField), and is not in any way tied
to the value of the field's blank option. The blank option, as noted in its
description, is used for validation and is not applied at the database
level.

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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