Search code examples
pythondjangoinspectdb

Django Inspectdb on MSSql error while trying to inspect a table


I've got this error while trying inspecting a MsSql database:

# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#   * Rearrange models' order
#   * Make sure each model has one field with primary_key=True
#   * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior
#   * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models
# Unable to inspect table 'test_table'
# The error was: __new__() missing 1 required positional argument: 'collation'

This is the command that I've used:

python manage.py inspectdb test_table --database=some_db --verbosity=3

This is the connection in settings.py:

  'some_db':{
        'ENGINE': 'sql_server.pyodbc',
        'NAME': os.environ['name'],
        'USER': os.environ['user'],
        'PASSWORD': os.environ['pw'],
        'HOST': os.environ['db'],
        'PORT': os.environ['port'],
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
            'unicode_results': True

        },
    }

Solution

  • I've found out that there was a version mismatch between Mssql version and pyodbc version: Mssql version was not supported. I solved using django-pyodbc-azure instead of pyodbc directly!