Skip to content

UniqueConstraint in Model Meta is not considered #330

@diesieben07

Description

@diesieben07

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

  1. Create a UniqueConstraint for a CharField via Model Meta.
  2. Try to clone the model.
  3. Observe IntegrityError being 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions