Opened 6 years ago

Closed 6 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 Tim Graham)

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)

comment:1 by Simon Charette, 6 years ago

Hello Ron,

Could you provide an exact reproduction case for your issue. From a quick look your models are not valid because field1 and field2 are not defined on your abstract model.

comment:2 by Ronny Vedrilla, 6 years ago

Description: modified (diff)

in reply to:  1 comment:3 by Ronny Vedrilla, 6 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 field1 and field2 are not defined on your abstract model.

comment:4 by Tim Graham, 6 years ago

Description: modified (diff)
Resolution: worksforme
Status: newclosed
Summary: Unique_together constraint not inherited from abstract model in migration fileunique_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.

Note: See TracTickets for help on using tickets.
Back to Top