模块'django.db.ackends.utils'没有属性'type_decimal' [英] module 'django.db.backends.utils' has no attribute 'typecast_decimal'

查看:291
本文介绍了模块'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

引用:


堆栈跟踪:

  1. 关于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
  1. 关于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'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆