-
-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Describe the bug
If a field is made unique via a UniqueConstraint it is not detected as unique and thus cloning the model will result in constraint errors instead of copy being appended to the field.
To Reproduce
- Create a
UniqueConstraintfor aCharFieldvia ModelMeta. - Try to clone the model.
- Observe
IntegrityErrorbeing thrown.
Expected behavior
UniqueConstraints should be detected.
Desktop (please complete the following information):
- Version 2.5.3
Additional context
I don't think the fix for this is simply treating the fields as unique and appending "copy" to them. While that will probably remove the constraint error, it might not be what is desired, as a UniqueConstraint might have multiple fields (the same applies to unique_together) or even a condition.
It would be useful to provide a hook for models / fields to provide their own "get new unique value"-logic. This would additionally enable fields other than CharField to work with unique.