this is my model:

class Visitor(meta.Model):
   title = meta.CharField('Title',maxlength=250)
   name = meta.CharField('Name',maxlength=100)
   email = meta.EmailField('Email Id')
   date = meta.DateField(auto_now_add=True)
   matter = meta.TextField('Matter')
   approved = meta.BooleanField('Approved',default='true')

i type this at the python prompt:

p = visitors.Visitor(title=l'title')
p.save()

it saves, pg doesnt barf, and i get '' values in all the text fields. I feel the behaviour should be a barf from pg.


That feeling would be incorrect though :). Which is why I made mention of
'' != NULL. It is an important distinction. A '' is a string, a blank string but
still a string. A NULL is nothing, it does not exist, and has no value.

As a counter example, an integer may be NULL but may not be '' .

In order for PostgreSQL to not allow a blank or null in the colum you would
have to have something like this:

CREATE TABLE foo (id bigserial primary key, name text check (name IS NOT NULL OR name !=''))

I believe the model would look like this:

class Visitor(meta.Model):
  name = meta.CharField('Name', maxlength=100,blank=False, null=False)

Here is a good explanation of NULL:

http://www.metrokc.gov/gis/kb/Content/SQLTipNull.htm

Sincerely,
Joshua D. Drake






--
The PostgreSQL Company - Command Prompt, Inc. 1.503.667.4564
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: PLphp, PLperl - http://www.commandprompt.com/

Reply via email to