Opened 7 years ago
Closed 7 years ago
#29588 closed Bug (worksforme)
unique_together constraint not inherited from abstract model in migration file
| Reported by: | Ronny Vedrilla | Owned by: | nobody |
|---|---|---|---|
| Component: | Migrations | Version: | 2.0 |
| Severity: | Normal | Keywords: | |
| 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 )
I added a unique_together constraint on my abstract model like this:
class InvoicingDocument(models.Model):
field1 = models.IntegerField()
field2 = models.IntegerField()
class Meta:
abstract = True
unique_together = (('field1', 'field2'),)
class Invoice(InvoicingDocument):
pass
When I run manage.py makemigrations the migration file does not contain any information about adding the index to the model Invoice.
When I add it to the child-class, it works.
I guess this is an issue with django-migrations?
Best regards
Ronny
Change History (4)
follow-up: 3 comment:1 by , 7 years ago
comment:2 by , 7 years ago
| Description: | modified (diff) |
|---|
comment:3 by , 7 years ago
Yep, you are right. Added the fields.
Replying to Simon Charette:
Hello Ron,
Could you provide an exact reproduction case for your issue. From a quick look your models are not valid because
field1andfield2are not defined on your abstract model.
comment:4 by , 7 years ago
| Description: | modified (diff) |
|---|---|
| Resolution: | → worksforme |
| Status: | new → closed |
| Summary: | Unique_together constraint not inherited from abstract model in migration file → unique_together constraint not inherited from abstract model in migration file |
Using that model, I see this migration:
# Generated by Django 2.0.8.dev20180716124449 on 2018-07-25 20:51
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Invoice',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('field1', models.IntegerField()),
('field2', models.IntegerField()),
],
options={
'abstract': False,
},
),
migrations.AlterUniqueTogether(
name='invoice',
unique_together={('field1', 'field2')},
),
]
If I've missed something, please be more explicit about the steps to reproduce the issue.
Hello Ron,
Could you provide an exact reproduction case for your issue. From a quick look your models are not valid because
field1andfield2are not defined on your abstract model.