#31834: Cannot sqlmigrate on Django migrations that change unique_together
-------------------------------------+-------------------------------------
Reporter: Brіаn Lаі | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.0
(models, ORM) |
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 Brіаn Lаі:
Old 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.
> ]
> }}}
New description:
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.
]
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/31834#comment:1>
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/062.20aa02219626c32f3c647beb90dc15ed%40djangoproject.com.