I am trying to connect a django project (Python 3.5.2 and Django 1.10.2) to a SQLServer database using django_mssql , but this is failing when creating django internal tables.
Here is what I added in settings.py
DATABASES = {
'default': {
'NAME': 'my_db',
'ENGINE': 'sqlserver_ado',
'HOST': 'my_server',
'USER': 'my_user',
'PASSWORD': 'super_secret_password',
'PORT': '',
'OPTIONS': {
'provider' : 'SQLNCLI11'
},
}
}
and when I try to start any transfer (even without any specific model), I get:
python manage.py migrate
(lot of logs here....)
django.db.utils.DatabaseError: (-2147352567, 'Exception occurred.', (0, 'Microso
ft SQL Server Native Client 11.0', "The object 'UQ__auth_use__F3DBC57228A1A130'
is dependent on column 'username'.", None, 0, -2147217900), None)
Command:
ALTER TABLE [auth_user] ALTER COLUMN [username] nvarchar(150) NOT NULL
Parameters:
[]
Indeed, the table exists, the username column is null, but, of course, we cannot change it, since there is a unique restriction in this column.
The script should abandon the constraint, change the column, recreate the constraint. Or don't create a constraint so early in the script.
I tried on SQLServer 2008 and 2014, the same thing happens.
SQLOLEDB SQLNCLI11, .
, , .
...
EDIT: : auth, .
: <path_to_python>\Lib\site-packages\django\contrib\auth\migrations :
- 0001_initial.py
- 0004_alter_user_username_opts.py
- 0007_alter_validators_add_error_messages.py
unique=True, .
, ...