django migrate error : 'Microsoft OLE DB Provider for SQL Server', "Cannot insert the value NULL into column 'last_login', table

401 Views Asked by At

I have installed below versions

Django==1.8

django-mssql==1.8

pypiwin32==220

pytz==2017.3

and my setting.py file is as below.

----------------Start of setting.py------------------

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'polls',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

"""DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}"""
DATABASES = {
    'default': {
        'NAME': 'shetdb',
        'ENGINE': 'sqlserver_ado',
        'HOST': '127.0.0.1',
        'USER': 'sa',
        'PASSWORD': 'ppp@123',
        'OPTIONS': {
            'provider': 'SQLOLEDB',
            'use_legacy_date_fields': 'True',
            'use_mars': True
        }
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

-------------------End of setting.py file----------------------------

with these settings , I am not able to create super user/admin for sample application. When i try to createsuperuser using command >python manage,py createsuperuser it asks for username/email and password (2 times) after entering and hitting enter, I am getting below error in console.

---------------------------start-----------------------------------------------

Email address: p@123
Error: Enter a valid email address.
Email address: [email protected]
Password:
Password (again):
Traceback (most recent call last):
  File "C:\Program Files\Python\lib\site-packages\sqlserver_ado\dbapi.py", line 547, in _execute_command
    recordset = self.cmd.Execute()
  File "<COMObject ADODB.Command>", line 3, in Execute
  File "C:\Program Files\Python\lib\site-packages\win32com\client\dynamic.py", line 287, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provider for SQL Server', "Cannot insert the value NULL into column 'last_login', table 'shetdb.dbo.auth_user'; column does not allow nulls. INSERT fails.", None, 0, -2147217873), None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python\lib\site-packages\django\db\backends\utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "C:\Program Files\Python\lib\site-packages\sqlserver_ado\dbapi.py", line 647, in execute
    self._execute_command()
  File "C:\Program Files\Python\lib\site-packages\sqlserver_ado\dbapi.py", line 558, in _execute_command
    self._raiseCursorError(klass, _message)
  File "C:\Program Files\Python\lib\site-packages\sqlserver_ado\dbapi.py", line 488, in _raiseCursorError
    eh(self.connection, self, errorclass, errorvalue)
  File "C:\Program Files\Python\lib\site-packages\sqlserver_ado\dbapi.py", line 103, in standardErrorHandler
    raise errorclass(errorvalue)
sqlserver_ado.dbapi.IntegrityError: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Provider for SQL Server', "Cannot insert the value NULL into column 'last_login', table 'shetdb.dbo.auth_user'; column does not allow nulls. INSERT fails.", None, 0, -2147217873), None)
Command:
SET NOCOUNT ON;DECLARE @sqlserver_ado_return_id table ([id] int);INSERT INTO [auth_user] ([password], [last_login], [is_superuser], [username], [first_name], [last_name], [email], [is_staff], [is_active], [date_joined]) OUTPUT INSERTED.[id] INTO @sqlserver_ado_return_id VALUES (?, NULL, ?, ?, '', '', ?, ?, ?, ?);SELECT * FROM @sqlserver_ado_return_id
Parameters:
['Name: p0, Dir.: Input, Type: adVarWChar, Size: 77, Value: '
 '"pbkdf2_sha256$20000$GlZS9GZjXEMH$A33R/aR6QaF4Gy9x92K6aYJNluWf/+T+GdoAwE91vJY=", '
 'Precision: 0, NumericScale: 0',
 'Name: p2, Dir.: Input, Type: adBoolean, Size: -1, Value: "True", Precision: '
 '0, NumericScale: 0',
 'Name: p3, Dir.: Input, Type: adVarWChar, Size: 12, Value: "praveenshetg", '
 'Precision: 0, NumericScale: 0',
 'Name: p6, Dir.: Input, Type: adVarWChar, Size: 9, Value: "[email protected]", '
 'Precision: 0, NumericScale: 0',
 'Name: p7, Dir.: Input, Type: adBoolean, Size: -1, Value: "True", Precision: '
 '0, NumericScale: 0',
 'Name: p8, Dir.: Input, Type: adBoolean, Size: -1, Value: "True", Precision: '
 '0, NumericScale: 0',
 'Name: p9, Dir.: Input, Type: adVarWChar, Size: 26, Value: '
 '"2017-11-07T10:58:39.397247", Precision: 0, NumericScale: 0']

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Program Files\Python\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "C:\Program Files\Python\lib\site-packages\django\core\management\__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)

-------------------------------end------------------------------ I tried removing admin and auth from installedapps settings it works fine but admin page is not accessible.

enter code here

Please suggest way to fix this to create super user and access admin page.

0

There are 0 best solutions below