I know there's a lot of confusion over empty strings and NULLs, and
I've read a bunch of the threads about them, but I can't seem to find a
solution to this problem:
Basically, I want to be able to leave a field blank in the admin, and
have it insert an empty string instead of a NULL into the database (so
that the field can be set to NOT NULL and PosgreSQL won't barf).
The docs seem to imply that Django will do this, but I can't get it to.
-----------
If True, Django will store empty values as NULL in the database.
Default is False.
Note that empty string values will always get stored as empty strings,
not as NULL -- so use null=True for non-string fields such as integers,
booleans and dates.
------------
Here's my field definition:
notes = models.CharField(maxlength=200, null=False, default='',
blank=True)
However, every time I try to use the admin to add a record where the
"notes" field is empty, I get an error from the database about
inserting a NULL value. Why doesn't it use the specified default? Do
I have to override the save() method or something?
Thanks.
submitted = models.DateTimeField('Date Submitted', auto_now_add=True)
And the SQL error:
ERROR: null value in column "submitted" violates not-null constraint
UPDATE "myapp_message" SET message"='Mauris nec mi eget turpis
tincidunt sodales',notes='',"user_id"='1',"submitted"=NULL WHERE
"id"='30'