Opened 17 years ago
Closed 13 years ago
#6189 closed Uncategorized (invalid)
IntegrityError: Field "may not be NULL" even though blank=True
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | integrityerror, blank, null |
Cc: | tyson@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Despite adding "blank=True" to my fields, I am unable to save them through the admin interface. I get errors like the following:
Environment: Request Method: POST Request URL: http://127.0.0.1:8000/admin/events/event/add/ Django Version: 0.97-pre-SVN-6914 Python Version: 2.4.4 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.flatpages', 'cptri.apps.events', 'cptri.apps.workouts', 'cptri.apps.members'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.doc.XViewMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware') Traceback: File "/opt/local/lib/python2.4/site-packages/django/core/handlers/base.py" in get_response 82. response = callback(request, *callback_args, **callback_kwargs) File "/opt/local/lib/python2.4/site-packages/django/contrib/admin/views/decorators.py" in _checklogin 56. return view_func(request, *args, **kwargs) File "/opt/local/lib/python2.4/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 39. response = view_func(request, *args, **kwargs) File "/opt/local/lib/python2.4/site-packages/django/contrib/admin/views/main.py" in add_stage 264. new_object = manipulator.save(new_data) File "/opt/local/lib/python2.4/site-packages/django/db/models/manipulators.py" in save 109. new_object.save() File "/opt/local/lib/python2.4/site-packages/django/db/models/base.py" in save 261. ','.join(placeholders)), db_values) File "/opt/local/lib/python2.4/site-packages/django/db/backends/util.py" in execute 18. return self.cursor.execute(sql, params) File "/opt/local/lib/python2.4/site-packages/django/db/backends/sqlite3/base.py" in execute 133. return Database.Cursor.execute(self, query, params) Exception Type: IntegrityError at /admin/events/event/add/ Exception Value: events_event.start_time may not be NULL
With the following model:
class Foo(models.Model): the_char = models.CharField(blank=True, maxlength=100) the_text = models.TextField(blank=True) the_integer = models.IntegerField(blank=True) the_time = models.TimeField(blank=True) the_date = models.DateField(blank=True) the_datetime = models.DateTimeField(blank=True) class Admin: pass def __str__(self): return "Foo"
The following fields, if left blank, give me the above error:
the_integer the_time the_date the_datetime
the_char
does not behave unexpectedly (e.g. it allows blank values without throwing an error).
Change History (5)
comment:1 by , 17 years ago
comment:2 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Use the null
option as well.
You are seeing documented behavior, see the descriptions of the null
(http://www.djangoproject.com/documentation/model-api/#null) and blank
field options (http://www.djangoproject.com/documentation/model-api/#blank) for more details.
comment:4 by , 13 years ago
Easy pickings: | unset |
---|---|
Resolution: | fixed |
Severity: | → Normal |
Status: | closed → reopened |
Type: | → Uncategorized |
UI/UX: | unset |
comment:5 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Sorry for the noise. I mis typed the ticket number in a commit message.
I forgot to add that
the_text
does not behave unexpectedly, either.