You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
An exception is thrown when running migrations using MSSQL as database backend. The error reported by SQL Server is the following:
The operation failed because an index or statistics with name 'rest_framework_api_key_apikey_prefix_4e0db5f8_uniq' already exists on table 'rest_framework_api_key_apikey'. (1913) (SQLExecDirectW).
Looking at the code in AbstractAPI I conjecture that the error is produced because of the definition of the id field:
id = models.CharField(max_length=100, unique=True, primary_key=True, editable=False)
My guess is that, for some reason, SQL Server is actually trying to create two times the same index because both primary_key AND unique are set to true. Even though this is probably a bug in django-mssql-backend, I'm reporting this here because it's my understanding that primary_key already implies unique and therefore it should not be necessary to set unique. Am I right?
To Reproduce
Steps to reproduce the behavior:
Set up a django project using django-mssql-backend as database backend and djangorestframework-api-key
Run migrations
See error
Desktop (please complete the following information):
OS: Linux and OSX
Python Version: 3.7
Django Version: 2.2
Django Rest Framework APIKey Version: 2.0.0
DRF Version: 3.11.0
django-mssql-backend Version: 2.8.1
The text was updated successfully, but these errors were encountered:
Actually not... and the exception comes from this 0004_prefix_hashed_key migration, so it seems has nothing to do with combining primary_key with unique.
I will do a more thorough research and get back with better insight. At this point it seems to be django-mssql-backend's fault completely.
Describe the bug
An exception is thrown when running migrations using MSSQL as database backend. The error reported by SQL Server is the following:
The operation failed because an index or statistics with name 'rest_framework_api_key_apikey_prefix_4e0db5f8_uniq' already exists on table 'rest_framework_api_key_apikey'. (1913) (SQLExecDirectW).
Looking at the code in
AbstractAPI
I conjecture that the error is produced because of the definition of theid
field:id = models.CharField(max_length=100, unique=True, primary_key=True, editable=False)
My guess is that, for some reason, SQL Server is actually trying to create two times the same index because both
primary_key
ANDunique
are set to true. Even though this is probably a bug in django-mssql-backend, I'm reporting this here because it's my understanding thatprimary_key
already impliesunique
and therefore it should not be necessary to setunique
. Am I right?To Reproduce
Steps to reproduce the behavior:
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: