blank and null with Oracle

19 views
Skip to first unread message

Skylar Saveland

unread,
Feb 27, 2013, 5:31:20 PM2/27/13
to django...@googlegroups.com
Some odd behavior with Oracle involving blank and null.

blank is True on this field:
my_auto = models.AutoField(blank=False, null=False, primary_key=True)

null is True on this field:
uncles = models.ManyToManyField(Uncle, blank=False, null=False) 

null is True on this field:
photo = models.ImageField(upload_to="uploads/") 

And, then, as documented null=True on CharFields.

The most disturbing thing is that blank/null on the first two examples are the opposite of what is explicitly declared.

Should I post this on django-developers. Is this behavior documented? Are this problems/quirks known?

-Skylar

Ian

unread,
Feb 28, 2013, 11:53:48 AM2/28/13
to django...@googlegroups.com
On Wednesday, February 27, 2013 3:31:20 PM UTC-7, Skylar Saveland wrote:
Some odd behavior with Oracle involving blank and null.

blank is True on this field:
my_auto = models.AutoField(blank=False, null=False, primary_key=True)

null is True on this field:
uncles = models.ManyToManyField(Uncle, blank=False, null=False)

These two have nothing to do with Oracle specifically.  AutoFields are coerced to blank=True regardless of backend.  You can see that here:

https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L534

I don't know exactly why this is done, but I would guess it is because the point of the AutoField is that it can be left blank and automatically be filled in.  If you don't want that, then you probably want an IntegerField instead.

I'm not sure where null=True is getting set on the ManyToManyField, but I guess that the reason for this is that null=False represents a database constraint, and there is no way to actually set that constraint because the field does not map to an actual column in the model table; it maps to an intermediate relational table instead.

null is True on this field:
photo = models.ImageField(upload_to="uploads/") 

This one is due to Oracle, because ImageField is a string-based field (it stores the filename where the image is stored).  A null value here in Oracle is equivalent to an empty filename in another backend.
 
And, then, as documented null=True on CharFields.

Note that the docs say, "fields that have the empty string as a possible value", not specifically CharFields.  This is because it also includes things like FileField, ImageField, CommaSeparatedIntegerField, GenericIPAddressField, etc.

Reply all
Reply to author
Forward
0 new messages