#23740: Cannot drop unique_together constraint on a single field with its own
unique=True constraint
---------------------------------+-----------------------------------------
Reporter: Mihail Milushev | Owner: David Wobrock
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: unique_together | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by David Wobrock):
* cc: David Wobrock (added)
* owner: nobody => David Wobrock
* has_patch: 0 => 1
* status: new => assigned
Comment:
Hey there,
It's indeed still (mostly) relevant.
I've tried to tackle the issue, here is a first draft of the
[https://github.com/django/django/pull/15732 PR].
"Mostly" because I couldn't reproduce the part that Matt is describing
about adding a `unique_together`:
> Another way this manifests itself is to perform the following steps, in
separate migrations:
>
> * create a model
> * add unique=True to one if its fields
> * add a unique_together constraint for that same field
>
> This results in two identical calls to _create_unique_sql, leading to a
'relation "foo_bar_name_1e64ed8ec8cfa1c7_uniq" already exists' error.
For the rest, removing the `unique_together` on a PK field and on a
`unique=True` field should work now, when we base the constraint checking
on how the `unique_together` names are generated by default.
However, this will break dropping such a constraint if it has been renamed
manually. I think this should be fine, as the name is generated by Django
and never really exposed - so I guess it's okay to regard this name as
internals of Django, and we can rely on it.
Feel free to tell me what you think of the PR :)
--
Ticket URL: <https://code.djangoproject.com/ticket/23740#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070180f6644637-c401837f-b8f9-4e89-8116-9fdb4c1522e7-000000%40eu-central-1.amazonses.com.