Opened 5 years ago
Closed 5 years ago
#31332 closed Bug (worksforme)
Constraint detection fails when altering unique_together on MySQL.
Reported by: | Aishwary | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.11 |
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 have a database table that currently has uniqueness constraint over three columns. I added one more column to this uniqueness constraint.
So, the Meta class with the new uniqueness constraints looks as follows:
class Meta: unique_together = ('batch_size', 'distributor', 'service', 'type')
On running makemigrations command, I get the following error:
Running migrations: Applying shopping.0061_alter_distributorprice_uniqueness_constraint...Traceback (most recent call last): ile "manage_lims.py", line 14, in <module> manage.main() File "/home/addgene/addgene-core/src/django/manage.py", line 20, in main execute_from_command_line(sys.argv) File "/srv/addgene-py3/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line utility.execute() File "/srv/addgene-py3/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/srv/addgene-py3/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File "/srv/addgene-py3/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, **options) File "/srv/addgene-py3/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle fake_initial=fake_initial, File "/srv/addgene-py3/lib/python3.5/site-packages/django/db/migrations/executor.py", line 115, in migrate state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial) File "/srv/addgene-py3/lib/python3.5/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "/srv/addgene-py3/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "/srv/addgene-py3/lib/python3.5/site-packages/django/db/migrations/migration.py", line 129, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "/srv/addgene-py3/lib/python3.5/site-packages/django/db/migrations/operations/models.py", line 536, in database_forwards getattr(new_model._meta, self.option_name, set()), File "/srv/addgene-py3/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 365, in alter_unique_together self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique) File "/srv/addgene-py3/lib/python3.5/site-packages/django/db/backends/mysql/schema.py", line 88, in _delete_composed_index return super(DatabaseSchemaEditor, self)._delete_composed_index(model, fields, *args) File "/srv/addgene-py3/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 394, in _delete_composed_index ", ".join(columns), ValueError: Found wrong number (0) of constraints for shopping_distributorprice(batch_size, distributor_id, service_id)
I have already viewed and tested the tickets related to this error but none work. I even tried to remove the constraint altogether to reapply a new one, but still I get the same error as above.
Change History (5)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|
comment:2 by , 5 years ago
Description: | modified (diff) |
---|
comment:3 by , 5 years ago
Description: | modified (diff) |
---|
comment:4 by , 5 years ago
Description: | modified (diff) |
---|
comment:5 by , 5 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Summary: | migration error → Constraint detection fails when altering unique_together on MySQL. |
Note:
See TracTickets
for help on using tickets.
It works for me on the current master. Django 1.11 doesn't receive bugfixes anymore so you have to reproduce this on Django 3.0+. Please feel-free to reopen this ticket if you can provide a sample project that fails on the current master branch.