#26624: Error when running sqlmigrate after dropping index (of index_together)
without actually migrating
-------------------------------------+-------------------------------------
Reporter: Akshesh Doshi | Owner: <default>
Type: Bug | Status: closed
Component: Migrations | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: sqlmigrate db- | Triage Stage: Accepted
indexes |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):
`index_together` is
[https://docs.djangoproject.com/en/dev/ref/models/options/#django.db.models.Options.unique_together
discouraged], but I don't see anywhere that it's been deprecated, and it
will exist in migrations indefinitely.
Where I'm seeing this issue is migrating from a model like this
{{{
class Meta:
unique_together = (("a", "b", "c"))
}}}
to a UniqueConstraint removing one field:
{{{
class Meta:
constraints = [
models.UniqueConstraint(
fields=("a", "b"), name="bug_report"
),
]
}}}
Then `migrate`, then `sqlmigrate` produces `ValueError: Found wrong number
(0) of constraints`, which is not the same as the original report (failure
is after migrate, not before)
If the unique constraint is a straight port (not removing any fields):
{{{
class Meta:
constraints = [
models.UniqueConstraint(
fields=("a", "b", "c"), name="bug_report"
),
]
}}}
... `sqlmigrate` no longer crashes after `migrate`, but does not produce
the correct SQL:
{{{
BEGIN;
--
-- Alter unique_together for cardxnodexwidget (0 constraint(s))
--
ALTER TABLE "table" DROP CONSTRAINT "bug_report"; -- should not say
"bug_report"
--
-- Create constraint jtw on model cardxnodexwidget
--
ALTER TABLE "table" ADD CONSTRAINT "bug_report" UNIQUE ("a", "b", "c");
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26624#comment:7>
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 visit
https://groups.google.com/d/msgid/django-updates/01070196f2997d98-6e8ab5d2-b566-4c0d-a1de-1b373d976e23-000000%40eu-central-1.amazonses.com.