我遵循了来自费城和其他人的各种教程,用django -mssql-后端安装django,但是没有成功。我认为连接是有效的,但是当它试图解析表时,我会得到一个排序错误,它无法通过。我正在运行的内容的规范如下:
'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模块,它连接到表并提取它们的信息。我最大的问题是,它结束于数据库中的~15个表,并抛出一个内存错误,不管我如何修复它。
我们非常感谢您在这个问题上的任何想法或帮助!
发布于 2021-04-28 17:29:21
通过独立测试确认,该问题在3.2版中确实是一个bug,并将被放入bug报告中。不过,我现在确实提出了一个解决办法,具体如下:
创建新的临时虚拟environment
python manage.py inspectdb --database=yourentry > yourentry.py中的Server数据库条目
一旦您为您想要在网站中使用的现有数据库创建了所有模型,您就可以抓取每个yourentry.py文件并将它们复制到子模型文件夹中,并将它们导入主models.py文件中。
当不再需要虚拟环境时,可以删除它。
https://stackoverflow.com/questions/67290155
复制相似问题