Install django mssql: DB initialization error

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, .

, ...

+4
3

, , 008 , , , , ( - ) .

( ) , , , , True . , 3 - , , .

,

manage.py migrate

.

, , , , . , , .

, "" :

... Lib\site-packages\django\contrib\auth\migrations\008_alter_user_username_max_length.py

, :

operations = [
    migrations.AlterField(
        model_name='user',
        name='username',
        field=models.CharField(
            max_length=150,
            unique=False,
        ),
    ),
    migrations.AlterField(
        model_name='user',
        name='username',
        field=models.CharField(
            error_messages={'unique': 'A user with that username already exists.'},
            help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.',
            max_length=150,
            unique=True,
            validators=[validators.UnicodeUsernameValidator() if six.PY3 else validators.ASCIIUsernameValidator()],
            verbose_name='username',
        ),
    ),
]
+1

,

, 008_alter_user_username_max_length ( Windows "C:\Python34\Lib\site-packages\django\contrib\auth\migrations"

23:

unique=True

i :

unique=False

i redid

python manage.py migrate

0

I have exactly the same problem, I tried the "weird workaround of the day", but didn't change anything. I am using django 1.8, with django-mssql version 1.8. my database is MS SQL 2012 Express.

I also tried using different providers, however only SQLOLEDB would connect in my case.

I ran the following command and got the result below, overpricing the files causing the problem

C:\djangocode\testsite01>python manage.py showmigrations --list
admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [ ] 0008_alter_user_username_max_length
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
sessions
 [ ] 0001_initial

I am using Python 3.4

-1
source

Source: https://habr.com/ru/post/1659079/


All Articles