You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use many models with OneToOneField with default unique=True.
I would like the user to be able to create a record in table Exam even if one or more records are marked as soft (logically) deleted and linked to the same record in table Followup.
But when I have a model with OneToOneField, if I deleted a record 1 in table Exam linked to a record 1 in table Followup and I try to recreate a record 2 in table Exam linked to the same record 1 from table Followup, I get an IntegrityError because the uniqueness is not respected.
I read about the possibility of "revive" a deleted object but that's not what I want. I want to have multiple deleted records but only one undeleted one that respects the integrity of the constraints.
I read the section on field uniqueness in the documentation where a unique constraint can be set to exclude deleted records.
I try to implement this UniqueConstraint but it doesn't works.
I try to customize a ModelManager to set _safedelete_visibility = DELETED_VISIBLE_BY_PK but doesn't seems to works.
In my Postgresql database, a soft deleted object is not accessible with Exam.objects.filter(uuid='my-uuid') wherease it is for non soft deleted objects.
A solution seems to change OneToOneField to ForeignKey and define UniqueConstraint in Class Meta as mentionned above.
But As ForeignKey reverse relation return a QuerySet and not a single object, I have to modify all my template to add ".first" to access a single Exam object from Followup object
I use many models with OneToOneField with default unique=True.
I would like the user to be able to create a record in table Exam even if one or more records are marked as soft (logically) deleted and linked to the same record in table Followup.
But when I have a model with OneToOneField, if I deleted a record 1 in table Exam linked to a record 1 in table Followup and I try to recreate a record 2 in table Exam linked to the same record 1 from table Followup, I get an IntegrityError because the uniqueness is not respected.
I read about the possibility of "revive" a deleted object but that's not what I want. I want to have multiple deleted records but only one undeleted one that respects the integrity of the constraints.
I read the section on field uniqueness in the documentation where a unique constraint can be set to exclude deleted records.
I try to implement this UniqueConstraint but it doesn't works.
I try to customize a ModelManager to set _safedelete_visibility = DELETED_VISIBLE_BY_PK but doesn't seems to works.
In my Postgresql database, a soft deleted object is not accessible with Exam.objects.filter(uuid='my-uuid') wherease it is for non soft deleted objects.
The text was updated successfully, but these errors were encountered: