1

我已经按照 philly 和其他人的各种教程使用 django-mssql-backend 设置 django,但没有运气。我认为连接正常,但是当它试图解析表时,我得到一个无法通过的排序规则错误。我正在运行的规格如下:

  • django-mssql-后端:2.8.1
  • django: 3.2
  • pyodbc:4.0.30
    'server':{
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'database',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': 'hostname of server',
        'PORT': '',
        'OPTIONS': {
            'driver': 'ODBC Driver 17 for SQL Server',
            'unicode_results': True,
        },
    }

当我尝试运行迁移类创建器或:

python manage.py inspectdb --database=server

我在输出中收到以下错误:

# 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 'ADObjectMemberships'
# The error was: __new__() missing 1 required positional argument: 'collation'
# Unable to inspect table 'ADObjects'
# The error was: __new__() missing 1 required positional argument: 'collation'

我确信这是可能的,因为我在安装了 django 1.8 并安装了旧的 django-pyodbc-azure 模块的情况下使用了不同的 venv,它连接到表并提取它们的信息。我遇到的最大问题是它停止在数据库中留下约 15 个表,并且无论我做什么来修复它都会引发内存错误。

非常感谢您对这个问题的任何想法或帮助!

4

1 回答 1

1

Confirmed through independent testing that the issue does appear to be a bug in version 3.2 and will put in a bug report. However I did come out with a workaround for now as follows:

  • Create new temporary virtual environment
  • Install django==3.0 pyodbc==4.0 django-mssql-backend==1.8
  • Create the database entry for the SQL Server in settings.py
  • run python manage.py inspectdb --database=yourentry > yourentry.py

Once you have created all the models for the existing database you want to use in your website you can grab each of the yourentry.py files and copy them to a submodel folder and import them into the main models.py file.

When the virtual environment is no longer needed it can be deleted.

于 2021-04-28T17:29:21.203 回答