Opened 17 years ago

Closed 17 years ago

#3593 closed (invalid)

Field default values don't seem to work as expected

Reported by: brosner@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: dev
Severity: 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

If I have the given model in an app:

class Products(models.Model):
	name = models.CharField(maxlength=150)
	list_price = models.CharField(max_digits=10, decimal_places=2, default=0.00, blank=True)
	price = models.CharField(max_digits=10, decimal_places=2)
	
	class Admin:
		pass

When adding a new product through the admin site you will get an IntegrityError saying that list_price may not be NULL. I have tested this with MySQL and SQLite and both result in this error. While I could change the value on the fly before saving the object, but the default parameter would seem like it should handle that for me.

Change History (2)

comment:1 by brosner@…, 17 years ago

That model name should be Product and not Products. ;)

comment:2 by Ramiro Morales <rm0 _at_ gmx.net>, 17 years ago

Resolution: invalid
Status: newclosed

In the future please direct such questions to the django-users mailing list. This is NOT the right place for this kind of questions.

Oh and read the documentation. max_digits and decimal_places are no valid options for a CharField

http://www.djangoproject.com/documentation/model_api/#charfield

http://www.djangoproject.com/documentation/model_api/#floatfield

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