Answer the question
In order to leave comments, you need to log in
How to do soft delete and use unique keys?
I have a books table that has a unique alias field.
I'm doing a "soft" deletion, now the deleted_at field has been added, and so that deleted books do not interfere with creating new ones with the same alias, I set a unique key to two fields: alias, deleted_at.
Now you can create new entries with the same alias, even if there is such a "deleted" entry.
But now there is a new problem: deleted_at is null by default, so you can create records with the same alias as many times as you want.
How to keep records unique?
Answer the question
In order to leave comments, you need to log in
I wouldn't use deleted_at as a flag that the entity has been deleted - it's more of a reference.
Would start the is_delete field
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question