On 13 kesä, 12:14, Dave E <dever...@innotts.co.uk> wrote:
> I have a Django blog app with data in the (SQLite) database and have
> installed South so that I can add a 'modified' date field to the
> 'Entry' model. The field will initially be blank so I need blank=True
> for Django's admin validation.
>
> However, since it will also be empty in the database, do I need
> null=True as well (since it is a date field and not a string-based
> field)?
>
> If it were a string-based field, would I need to populate it with an
> empty string instead of null?
>
> I've read James Bennet's post and the Django docs (links below), but
> can't fathom the correct approach for this case:
>  http://www.b-list.org/weblog/2006/jun/28/django-tips-difference-betwe...
>
>  http://docs.djangoproject.com/en/dev/ref/models/fields/

The difference between null=True and blank=True is as follows:
null=True means that the database will not check that the column has
some value other than null. blank=True is only for the admin app (and
IIRC ModelForms) meaning that the form validation will check that
there is some value other than None in the field. So, the first is for
database, the last for Django form validation.

If you don't define null=True the database will enforce that all rows
are not null. Of course when you add a field into the database, the
row will have a null value by default for the old rows, and the
database will give you an error.

If null values are Ok for the field, you should add null=True. If not,
you should add some default value for the field by running a command
something like "alter table foo add column bar timestamp not null
default '2009-01-01';" in the dbshell. As you can't know the modified
timestamp values for the old rows, I would probably allow null values
for the column, and the meaning of null would be 'not known'.

Anssi

-- 
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