saxix/django-adminactions

IntegrityError on saving a related instance with unique=True on the relation field or on a OneToOneField

int-ua opened this issue · 3 comments

When both master and other have related OneToOne objects:

IntegrityError: duplicate key value violates unique constraint
"common_relatedmodel_connection_id_########_uniq"
DETAIL:  Key (connection_id)=(20147) already exists

Any ideas on a solution or a workaround?

Also, test_merge_one_to_one_field isn't testing OneToOneField, LogEntry is connected to user through a ForeignKey at least in Django 1.8.

saxix commented

do not see how to solve this with code. Seems an invalid "business" scenario, we can only catch the error and let the user fix the merge, removing (blanking) one of the field.

Just ran into this myself after testing implementing this into a project.

My suggested implementation would be if the the resulting unique records would match that the record that is trying to be changed should be deleted. If the records don't match then the two records could be then displayed in the same merge interface.