Opened 14 years ago

Closed 12 years ago

#189 closed defect (fixed)

Inline editing of foreign keys doesn't do pretty error handling.

Reported by: Nick Stenning Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords: admin interface error handling schema null fields
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When adding/editing foreign keys in the admin interface, any violation of NOT NULL or other schema specifications will throw a traceback rather than a pretty "this is what you did wrong" explanation when adding foreign keys manually.

There's been an error:

Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/handlers/", line 63, in get_response
    return callback(request, **param_dict)

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/views/admin/", line 860, in change_stage
    new_object =

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/", line 87, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/", line 1479, in manipulator_save

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/", line 87, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/", line 765, in method_save
    (opts.db_table, ','.join(field_names), ','.join(placeholders)), db_values)

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/db/", line 10, in execute
    result = self.cursor.execute(sql, params)

IntegrityError: ERROR:  null value in column "votes" violates not-null constraint

INSERT INTO polls_choices (poll_id,choice,votes) VALUES ('1','This is making me hungry ;-)',NULL)

Change History (3)

comment:1 Changed 14 years ago by Adrian Holovaty

Resolution: invalid
Status: newclosed

It's your responsibility to add blank=True to a field that has null=True if you want the admin to complain about blank values.

comment:2 Changed 14 years ago by marcink

Resolution: invalid
Status: closedreopened

Could we change the tutorial to contain either the 'blank=True' parameter or a warning that this will happen? The stack trace does not look like it was there by design and spoils the first impression a bit.

comment:3 Changed 12 years ago by Gary Wilson

Resolution: fixed
Status: reopenedclosed

There is now a note in the model-api docs that describes what blank=True does.

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