IntegrityError UNIQUE constraint failed: wishlists_wishlistinvitation.email, wishlists_wishlistinvitation.wishlist_id

Raised by:

django/db/backends/sqlite3/base.py (line 318)

Traceback (most recent call last):
  File "python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "python2.7/site-packages/django/utils/decorators.py", line 145, in inner
    return func(*args, **kwargs)
  File "python2.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "private.py", line 1, in private_function
    private_function()
  File "python2.7/site-packages/guardian/mixins.py", line 51, in dispatch
    )(request, *args, **kwargs)
  File "python2.7/site-packages/django/contrib/auth/decorators.py", line 22, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "python2.7/site-packages/oscar/apps/customer/wishlists/views.py", line 47, in dispatch
    **kwargs)
  File "python2.7/site-packages/django/views/generic/base.py", line 89, in dispatch
    return handler(request, *args, **kwargs)
  File "python2.7/site-packages/django/views/generic/edit.py", line 215, in post
    return self.form_valid(form)
  File "private.py", line 1, in private_function
    private_function()
  File "python2.7/site-packages/django/forms/models.py", line 463, in save
    construct=False)
  File "python2.7/site-packages/django/forms/models.py", line 105, in save_instance
    instance.save()
  File "python2.7/site-packages/django/db/models/base.py", line 710, in save
    force_update=force_update, update_fields=update_fields)
  File "python2.7/site-packages/django/db/models/base.py", line 738, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "python2.7/site-packages/django/db/models/base.py", line 822, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "python2.7/site-packages/django/db/models/base.py", line 861, in _do_insert
    using=using, raw=raw)
  File "python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "python2.7/site-packages/django/db/models/query.py", line 920, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "python2.7/site-packages/django/db/models/sql/compiler.py", line 974, in execute_sql
    cursor.execute(sql, params)
  File "python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "python2.7/site-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "python2.7/site-packages/django/db/backends/sqlite3/base.py", line 318, in execute
    return Database.Cursor.execute(self, query, params)
IntegrityError: UNIQUE constraint failed: wishlists_wishlistinvitation.email, wishlists_wishlistinvitation.wishlist_id

How to reproduce

Create a Model with unique_together and a ModelForm with fields missing one of the fields in the unique_together. And try to submit a form that try to create a model that breaks the unique togetherness.

How to fix

Add the field to to the ModelForm as a HiddenInput.