Code

Opened 6 years ago

Closed 3 years ago

#6189 closed Uncategorized (invalid)

IntegrityError: Field "may not be NULL" even though blank=True

Reported by: Tyson Tate <tyson@…> Owned by: nobody
Component: contrib.admin Version: master
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).

Attachments (0)

Change History (5)

comment:1 Changed 6 years ago by Tyson Tate <tyson@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I forgot to add that the_text does not behave unexpectedly, either.

comment:2 Changed 6 years ago by ramiro

  • Resolution set to invalid
  • Status changed from new to 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:3 Changed 3 years ago by ramiro

  • Resolution changed from invalid to fixed

In [16451]:

Fixed #6189 -- Modified test that need Internet access so they use a mock instead. Thanks Gregor Müellegger for the patch.

comment:4 Changed 3 years ago by ramiro

  • Easy pickings unset
  • Resolution fixed deleted
  • Severity set to Normal
  • Status changed from closed to reopened
  • Type set to Uncategorized
  • UI/UX unset

comment:5 Changed 3 years ago by ramiro

  • Resolution set to invalid
  • Status changed from reopened to closed

Sorry for the noise. I mis typed the ticket number in a commit message.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.