Opened 4 years ago

Last modified 4 years ago

#31834 closed Bug

Cannot sqlmigrate on Django migrations that change unique_together — at Version 1

Reported by: Brіаn Lаі Owned by: nobody
Component: Migrations Version: 3.0
Severity: Normal Keywords: sqlmigrate
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Brіаn Lаі)

Somewhat similar to #26624, but forward sqlmigrate, reproduced on Django 3.0.8 and Postgres 10.x.

If a model has a unique_together of

unique_together = [
    (a, b)
]

and it becomes

unique_together = [
    (a, b, c)
]

, although the makemigrations command successfully generates a new migration with the corresponding AlterUniqueTogether() operation, the migration cannot be inspected with the sqlmigrate command.

Reproduce bug with the following (the project may also be attached)

class Model1(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=255, unique=True)


class Model2(models.Model):
    id = models.IntegerField(primary_key=True)
    link_id = models.CharField(max_length=255)
    settings = models.ForeignKey(Model1, on_delete=models.CASCADE)


class Model3(models.Model):
    id = models.IntegerField(primary_key=True)
    order = models.IntegerField()
    model_2 = models.ForeignKey(Model2, on_delete=models.CASCADE)
    direct = models.BooleanField(default=True)

    class Meta:
        unique_together = [
            ('model_2', 'order')
            # To get the bug, change this to ('model_2', 'order', 'direct') and sqlmigrate the migration that this creates.
        ]

Change History (2)

by Brіаn Lаі, 4 years ago

Attachment: foo.tar.gz added

Bug demo project

comment:1 by Brіаn Lаі, 4 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top