[Django] #33736: Unable to sqlmigrate on an AlterUniqueTogether migration

27 views
Skip to first unread message

Django

unread,
May 23, 2022, 8:13:25 AM5/23/22
to django-...@googlegroups.com
#33736: Unable to sqlmigrate on an AlterUniqueTogether migration
-------------------------------------+-------------------------------------
Reporter: Noelia | Owner: nobody
Marí Salvador |
Type: Bug | Status: new
Component: | Version: 4.0
Migrations |
Severity: Normal | Keywords: sqlmigrate
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Reproduced in Django 4.0.4.

Given this model:
{{{
class TestModel(models.Model):
name = models.CharField(max_length=200)
age = models.IntegerField()
colour = models.CharField(max_length=200)

class Meta:
unique_together = ["name", "age"]
}}}

When migrations are created and applied, a unique constraint is created on
the database. Now, we want to alter the unique_together to:
`unique_together = ["name", "colour"]`

After running `makemigrations`, **without applying the new migration**, we
are able to run `sqlmigrate`:
{{{
$ testproject python3 manage.py sqlmigrate core 0003
BEGIN;
--
-- Alter unique_together for testmodel (1 constraint(s))
--
DROP INDEX "core_testmodel_name_age_530d7841_uniq";
CREATE UNIQUE INDEX "core_testmodel_name_colour_5002f5dd_uniq" ON
"core_testmodel" ("name", "colour");
COMMIT;
}}}

However, after we successfully apply migrations as below, `sqlmigrate`
fails.
{{{
$ testproject python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, core, sessions
Running migrations:
Applying core.0003_alter_testmodel_unique_together... OK
}}}

So when running `sqlmigrate` on the same migration it crashes and throws a
`ValueError` because it's looking for the prior index:
{{{
$ testproject python3 manage.py sqlmigrate core 0003
Traceback (most recent call last):
...
raise ValueError(
ValueError: Found wrong number (0) of constraints for core_testmodel(name,
age)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33736>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 23, 2022, 8:24:23 AM5/23/22
to django-...@googlegroups.com
#33736: Unable to sqlmigrate on an AlterUniqueTogether migration
-------------------------------------+-------------------------------------
Reporter: Noelia Marí | Owner: nobody

Salvador |
Type: Bug | Status: new
Component: Migrations | Version: 4.0
Severity: Normal | Resolution:
Keywords: sqlmigrate | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Noelia Marí Salvador:

Old description:

New description:

Reproduced in Django 4.0.4.

Full minimal example can be found here:
https://github.com/AledWatkins/sqlmigrate-failures

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33736#comment:1>

Django

unread,
May 23, 2022, 11:36:05 AM5/23/22
to django-...@googlegroups.com
#33736: Unable to sqlmigrate on an AlterUniqueTogether migration
-------------------------------------+-------------------------------------
Reporter: Noelia Marí | Owner: nobody
Salvador |
Type: Bug | Status: closed
Component: Migrations | Version: 4.0
Severity: Normal | Resolution: duplicate

Keywords: sqlmigrate | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #31834.

--
Ticket URL: <https://code.djangoproject.com/ticket/33736#comment:2>

Reply all
Reply to author
Forward
0 new messages