[Solved] Doctrine 2 @Gedmo\SoftDeleteable and unique fields


Do you know what means “soft delete”? It means that every “delete” operation will be converted to SQL that only set some deleted flag to true. And if you will insert another row with the same value of unique field that have soft deleted row you will get this message.

You have two ways to solve this problem:

  • Make your unique index with two columns: your original unique field and deleted flag. Then you will get this error only when you try to add row with the existing unique fields values only for not soft deleted.
  • Avoid making this violation: you should exclude the possibility to add row that duplicates another in unique fields.

The second one is the best approach IMHO.

1

solved Doctrine 2 @Gedmo\SoftDeleteable and unique fields