1

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

        },
    }

4 Answers4

2

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!

1

There seem to be some collation changes in djagno 3.2 that cause this issue, and unfortunately django-mssql-backend doesn't officially support django 3.2 (as of Nov 2021).

see: https://code.djangoproject.com/ticket/32767

While I am able to run django-mssql-backend with django 3.2 in most cases, I temporarily revert to django 3.1 in order to perform inspectdb

Related discussions at: https://stackoverflow.com/a/67305117/341329

Aaron
  • 2,409
  • 29
  • 18
1

The third-party backend django-mssql-backend still has this issue for Django 3.2. However, there is now a fork of django-mssql-backend called mssql-django that is maintained by Microsoft. This new fork does say it supports Django 3.2 and worked for me.

https://github.com/microsoft/mssql-django

John Meinken
  • 439
  • 4
  • 10
0

I had the same problem, but found the solution: The user wasn't part of the db_owner role. In other words you probably don't have enough permissions. Make the user owner of the database in your mssql.