本文介紹了模塊';django.db.ackends.utils';沒有屬性';type_decimal';的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
當我運行時
python manage.py inspectdb --database=sybase_database
以錯誤消息結束:
Database.register_converter(Database.DT_DECIMAL, util.typecast_decimal) AttributeError: module 'django.db.backends.utils' has no attribute 'typecast_decimal'
$ pip freeze
certifi==2021.10.8
chardet==3.0.4
defusedxml==0.7.1
Django==2.2.4
django-allauth==0.40.0
django-bootstrap-form==3.4
django-bootstrap3==15.0.0
django-crispy-forms==1.7.2
django-crudbuilder==0.2.7
django-debug-toolbar==1.10.1
django-filter==2.2.0
django-mssql-backend==2.8.1
django-tables2==2.4.1
idna==2.8
importlib-metadata==2.1.1
oauthlib==3.1.1
pyodbc==4.0.32
python-dateutil==2.8.2
python3-openid==3.2.0
pytz==2021.3
requests==2.21.0
requests-oauthlib==1.3.0
six==1.16.0
sqlany-django==1.13
sqlanydb==1.0.11
sqlparse==0.4.2
urllib3==1.24.3
zipp==3.6.0
Ubuntu 18.04
推薦答案
sqlany-django
最高僅支持Django 1.8.5(inspectdb
命令的Django 1.7.0)。
不再維護;上次更新是在2016年5月。
您可以在made.py或AppConfig
中修補Django的更高版本。
# Django >= 2.0, for sqlany_django/base.py
import decimal
from django.db.backends import utils
utils.typecast_decimal = decimal.Decimal
# Django >= 1.11, for BaseDatabaseWrapper
from sqlany_django.base import DatabaseWrapper
DatabaseWrapper.client_class = lambda self, connection: None
DatabaseWrapper.creation_class = lambda self, connection: None
DatabaseWrapper.features_class = lambda self, connection: None
DatabaseWrapper.introspection_class = lambda self, connection: None
DatabaseWrapper.ops_class = lambda self, connection: None
# Django >= 1.7.1, for inspectdb
from django.db.backends import utils
from sqlany_django import base
class CursorWrapper(base.CursorWrapper, utils.CursorWrapper):
pass
base.CursorWrapper = CursorWrapper
引用:
https://github.com/django/django/pull/2154關于CursorWrapper
https://github.com/django/django/pull/7206關于DatabaseWrapper
https://github.com/django/django/pull/8889關于typecast_decimal
https://github.com/sqlanywhere/sqlany-django/pull/15關于typecast_decimal
https://sqlanywhere-forum.sap.com/questions/37563/sqlany-django-driver-upgrade-to-django-32請求更新sqlany_django
(截至本帖子未回復)
堆棧跟蹤:
-
關于
DatabaseWrapper
Traceback (most recent call last):
...
File "/path/to/site-packages/django/core/management/commands/inspectdb.py", line 40, in handle_inspection
connection = connections[options['database']]
File "/path/to/site-packages/django/db/utils.py", line 207, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/path/to/site-packages/sqlany_django/base.py", line 447, in __init__
super(DatabaseWrapper, self).__init__(*args, **kwargs)
File "/path/to/site-packages/django/db/backends/base/base.py", line 102, in __init__
self.client = self.client_class(self)
TypeError: 'NoneType' object is not callable
-
關于
CursorWrapper
Traceback (most recent call last):
...
File "/path/to/site-packages/django/core/management/commands/inspectdb.py", line 47, in handle_inspection
with connection.cursor() as cursor:
AttributeError: __enter__
這篇關于模塊';django.db.ackends.utils';沒有屬性';type_decimal';的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,