Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#21854 closed Bug (invalid)

CharField has default value of u''

Reported by: burhan.khalid@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

>>> import django
>>> django.VERSION
(1, 6, 1, 'final', 0)
>>> from myfirstapp.models import Product
>>> p = Product()
>>> p
<Product: Product object>
>>> p.save()
>>> p.name
u''

Django should not save the object because the model definition is:

class Product(models.Model):
	name = models.CharField('product name', max_length=64)
	url = models.URLField('product page', blank=True)
	category = models.CharField(max_length=64, blank=True)
	description = models.TextField('product description', blank=True)

I am using 2.7.6

$ python
Python 2.7.6 (default, Dec 31 2013, 11:53:45)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin

Change History (3)

comment:1 by Marc Tamlyn, 11 years ago

Saving the model does not validate it. If you wish to check, you should call clean() on the instance. If the object is created via a form, this will happen. This is not likely to change.

comment:2 by Marc Tamlyn, 11 years ago

Resolution: invalid
Status: newclosed

comment:3 by anonymous, 11 years ago

The question is not about validation, its about setting a default value when no default value was specified in the model definition.

Note: See TracTickets for help on using tickets.
Back to Top