1
votes

I'm trying to use django-mssql to connect to MS SQL Server 2016 with Django 1.11 These are my Database settings:

DATABASE_ENGINE   = 'sqlserver_ado'
DATABASE_NAME     = 'db'
DATABASE_USER     = 'sa'
DATABASE_PASSWORD = '*********'
DATABASE_HOST     = 'localhost'

This is the error I get when I try run python manage.py runserver

(mywork) C:\Users\Kaushal_K\Python Dev\producttimeline>python manage.py runserver Unhandled exception in thread started by Traceback (most recent call last):

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\utils\autoreload.py", line 227, in wrapper fn(*args, **kwargs)

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run autoreload.raise_last_exception()

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\utils\autoreload.py", line 250, in raise_last_exception six.reraise(*_exception)

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\utils\autoreload.py", line 227, in wrapper fn(*args, **kwargs)

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\apps\registry.py", line 108, in populate app_config.import_models()

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\apps\config.py", line 202, in import_models self.models_module = import_module(models_module_name)

File "c:\python27\Lib\importlib__init__.py", line 37, in import_module import(name)

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\contrib\auth\models.py", line 4, in from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\contrib\auth\base_user.py", line 52, in class AbstractBaseUser(models.Model):

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\db\models\base.py", line 124, in new new_class.add_to_class('_meta', Options(meta, app_label))

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\db\models\base.py", line 330, in add_to_class value.contribute_to_class(cls, name)

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\db\models\options.py", line 214, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\db__init__.py", line 33, in getattr return getattr(connections[DEFAULT_DB_ALIAS], item)

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\db\utils.py", line 212, in getitem conn = backend.DatabaseWrapper(db, alias)

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\sqlserver_ado\base.py", line 184, in init super(DatabaseWrapper, self).init(*args, **kwargs)

File "C:\Users\Kaushal_K\Envs\mywork\lib\site-packages\django\db\backends\base\base.py", line 96, in init self.client = self.client_class(self)

TypeError: Error when calling the metaclass bases 'NoneType' object is not callable ^C

I've looked everywhere and I cannot seem to understand and fix the problem. I hope someone can help! Thanks!

PS:I've already created the database.

2
Facing the same issue here connecting to MSSQL 2014.Alan B

2 Answers

0
votes

Had the same problem. Then looked there - https://pypi.org/project/django-mssql/ - "Django version: 1.8". Tried to install it - and yeah, it works with django-mssql==1.8. Luckily for this particular need I can stay with this old version of Django.

Update. Now the next problem - "ImportError: No module named pythoncom". And "pip install pywin32" also doesn't work.