﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31332	Constraint detection fails when altering unique_together on MySQL.	Aishwary	nobody	"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."	Bug	closed	Migrations	1.11	Normal	worksforme			Unreviewed	0	0	0	0	0	0
