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 27946 Removing unique_together creates invalid migration Robin Elvin nobody "I had a model which had a unique_together constraint defined. Now I wish to remove this so the unique_together was removed from the model and a migration created. When applying the migration the following error occurred: {{{ Applying main.0091_auto_20170316_1046...Traceback (most recent call last): File ""manage.py"", line 8, in execute_from_command_line(sys.argv) File ""/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py"", line 354, in execute_from_command_line utility.execute() File ""/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py"", line 346, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File ""/usr/local/lib/python2.7/site-packages/django/core/management/base.py"", line 394, in run_from_argv self.execute(*args, **cmd_options) File ""/usr/local/lib/python2.7/site-packages/django/core/management/base.py"", line 445, in execute output = self.handle(*args, **options) File ""/usr/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py"", line 222, in handle executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial) File ""/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py"", line 110, in migrate self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial) File ""/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py"", line 148, in apply_migration state = migration.apply(state, schema_editor) File ""/usr/local/lib/python2.7/site-packages/django/db/migrations/migration.py"", line 115, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File ""/usr/local/lib/python2.7/site-packages/django/db/migrations/operations/models.py"", line 359, in database_forwards getattr(new_model._meta, self.option_name, set()), File ""/usr/local/lib/python2.7/site-packages/django/db/backends/base/schema.py"", line 320, in alter_unique_together self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique) File ""/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/schema.py"", line 80, in _delete_composed_index return super(DatabaseSchemaEditor, self)._delete_composed_index(model, fields, *args) File ""/usr/local/lib/python2.7/site-packages/django/db/backends/base/schema.py"", line 349, in _delete_composed_index "", "".join(columns), ValueError: Found wrong number (0) of constraints for main_projectdrivefile(name, directory_id) }}} The model's Meta before starting which was subsequently removed prior to creating the migration: {{{ #!python class Meta: unique_together = ('name', 'directory') }}} The migration created looks like this: {{{ #!python class Migration(migrations.Migration): dependencies = [ ('main', '0090_auto_20170314_1033'), ] operations = [ migrations.AlterUniqueTogether( name='projectdrivefile', unique_together=set([]), ), ] }}} Steps to reproduce: 1. Create a model with a unique_together constraint 2. Create a migration for this model with makemigrations 3. Apply migration 4. Remove unique_together completely 5. Create a migration for this model with makemigrations 6. Apply migration Note: There appears to have been at least 1 report of this bug previously but the reporter could not recreate so the bug was closed." Uncategorized new Migrations 1.8 Normal Unreviewed 0 0 0 0 0 0