[Django]-Django migration OperationalError: index [name] already exists

0👍

In my case, I copied migrations folder from an existing folder to a new folder. The migrations were already run. The migration file also added index with a name. When I copied the migrations folder to this new folder and tried running python manage.py migrate, it errored out because in the db, there was already an index with the same name.

Resolution: Just change the name of the index in the new migrations files!

This was a part of migrations file. Note that this file already existed and I created another copy and then tried running it again.

migrations.AddIndex(
            model_name='slackinstallation',
            index=models.Index(fields=['client_id', 'enterprise_id', 'team_id', 'user_id', 'installed_at'], name='slack_bot_s_client__63314d_idx'),
        ),

Changing the name of the index to anything different worked. Just for reference, I modified the name like this:

migrations.AddIndex(
            model_name='slackinstallation',
            index=models.Index(fields=['client_id', 'enterprise_id', 'team_id', 'user_id', 'installed_at'], name='slack_bot_v2_s_client__63314d_idx'),
        ),

Leave a comment