Monday, July 29, 2013

Django not enforcing blank=False on a model

Hi,

I have a model
from django.db import models    class Organization(models.Model):      name = models.CharField(max_length=100,                              blank = False,  #mandatory                              help_text = "Name of your Organization",                              verbose_name = '',                              unique = True,                              primary_key = True,                              )

and a piece of code
from organization.models import Organization
o = Organization.objects.create() 
o.save() 

which works without raising an IntegrityError! And the following also works just the same!
from organization.models import Organization
o = Organization() 
o.save() 

I am using SQLite3(SQLite 3.7.9 2011-11-01 00:52:41 c7c6050ef060877ebe77b41d959e9df13f8c9b5e) as the database backend and it shows the following as the schema:

CREATE TABLE "organization_organization" ( "name" varchar(100) NOT NULL PRIMARY KEY ); 
 
Even if SQLite3 was buggy, shouldn't Django itself enforce the constraint on ORM layer ?

I have deleted .pyc files and also the .sqlite3 file before testing again. I am using Django 1.5.1

What am I missing ? Why is Django NOT enforcing blank=False ?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment