Opened 4 years ago
Last modified 4 years ago
#31834 closed Bug
Cannot sqlmigrate on Django migrations that change unique_together — at Initial Version
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
Somewhat similar to #26624, but forward sqlmigrate, reproduced on Django 3.0.8 and Postgres 10.x.
If a model with a unique_together of
unique_together = [ (a, b) ]
and then this becomes
unique_together = [ (a, b, c) ]
, although the makemigrations command successfully generates the corresponding AlterUniqueTogether() operation, the operation 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. ]
Note:
See TracTickets
for help on using tickets.
Bug demo project