MultiValueDictKeyError in Django admin

I think it is related to a Django 1.6 ticket

#ticket 13696 -- ensured inline pk field is rendered

You have to update the following admin templates:

  • stacked.html
  • tabular.html

Remove the single line:

{% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}

and add the lines:

{% if inline_admin_form.needs_explicit_pk_field %}
    {{ inline_admin_form.pk_field.field }}
{% endif %}

If you are already on a newer version of django and still get this, make sure your non-AutoField PK has "editable=False" in the model definition.


For Django <= 1.7.3, also make sure, that the primary key field of your inline model is an AutoField:

wrong:

class Car(models.Model):
    id = IntegerField(primary_key=True)

correct:

class Car(models.Model):
    id = AutoField(primary_key=True)

See https://code.djangoproject.com/ticket/15665