Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24934 closed Bug (fixed)

Can't drop or change unique_together index

Reported by: user0007 Owned by: nobody
Component: Migrations Version: 1.8
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 user0007)

Hello,

I'm using Django 1.8.2 and Mysql 5.6. I created model with two fields in unique_together:

    user = models.ForeignKey(User)
    product = models.ForeignKey(Product)

    class Meta:
        unique_together = ('user', 'product')

the table was created successfully with following indexes:

PRIMARY                                     |            1 | id
myapp_mymodel_user_id_16c33dde7f7257bb_uniq |            1 | user_id
myapp_mymodel_user_id_16c33dde7f7257bb_uniq |            2 | product_id
myapp_mymodel_1ba366c5                      |            1 | user_id
myapp_mymodel_9bea82de                      |            1 | product_id

Later I removed unique_together from my model:

    class Meta:
        pass

so Django generated a migration:

    operations = [
        migrations.AlterUniqueTogether(
            name='mymodel',
            unique_together=set([]),
        ),
    ]

but when i try to apply this migrattion I have got an error:

    django.db.utils.OperationalError: (1061, "Duplicate key name 'myapp_mymodel_1ba366c5'")

Django is trying to create this index, instead of removed them.

The same situation is when I try to add third field to my unique_together list:

    class Meta:
        unique_together = ('user', 'product', 'category')
    django.db.utils.OperationalError: (1061, "Duplicate key name 'myapp_mymodel_1ba366c5'")

PS. The table was created using Django 1.7.X but changes was made using Django 1.8.2

Change History (6)

comment:1 by user0007, 9 years ago

Description: modified (diff)

comment:2 by user0007, 9 years ago

Description: modified (diff)

comment:3 by user0007, 9 years ago

Description: modified (diff)

comment:4 by user0007, 9 years ago

Summary: Can't drop or change unique_together index in MySqlCan't drop or change unique_together index

comment:5 by user0007, 9 years ago

Resolution: fixed
Status: newclosed

comment:6 by Tim Graham, 9 years ago

Did you resolve the issue? (not sure why the ticket was marked "fixed"). #24972 seems to report the same or similar issue.

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